Advertisement
Guest User

arduino Koffiemod

a guest
Jul 2nd, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #include <ShiftLCD.h>
  2.  
  3.  
  4. #define NUMBER_OF_SHIFT_CHIPS 1
  5. #define DATA_WIDTH NUMBER_OF_SHIFT_CHIPS * 8
  6. #define PULSE_WIDTH_USEC 5
  7. #define POLL_DELAY_MSEC 1
  8. #define BYTES_VAL_T unsigned int
  9.  
  10.  
  11. // initialize the library with the numbers of the interface pins
  12. ShiftLCD lcd(2, 4, 3);
  13. // id 2 data ic1
  14. // id 3 IC pin 12, Clock, Storage Register Clock input ST_CP
  15. // id 4 IC pin 11, Strobe, Clock input SH_CP
  16.  
  17. //Pin connected to latch pin (ST_CP) of 74HC595
  18. const int latchPin = 3;
  19. //Pin connected to clock pin (SH_CP) of 74HC595
  20. const int clockPin = 4;
  21. ////Pin connected to Data in (DS) of 74HC595
  22. const int dataPin = 5;
  23. char inputString[2];
  24.  
  25. int ploadPin = 7; // Connects to Parallel load pin the 165
  26. //int clockEnablePin = 9; // Connects to Clock Enable pin the 165
  27. int inputdataPin = 6; // Connects to the Q7 pin the 165
  28. int inputclockPin =8; // Connects to the Clock pin the 165
  29.  
  30. BYTES_VAL_T pinValues;
  31. BYTES_VAL_T oldPinValues;
  32.  
  33. BYTES_VAL_T read_shift_regs()
  34. {
  35. byte bitVal;
  36. BYTES_VAL_T bytesVal = 0;
  37.  
  38. /* Trigger a parallel Load to latch the state of the data lines,
  39. */
  40.  
  41. digitalWrite(ploadPin, LOW);
  42. delayMicroseconds(PULSE_WIDTH_USEC);
  43. digitalWrite(ploadPin, HIGH);
  44.  
  45. /* Loop to read each bit value from the serial out line
  46. * of the SN74HC165N.
  47. */
  48. for(int i = 0; i < DATA_WIDTH; i++)
  49. {
  50. bitVal = digitalRead(inputdataPin);
  51.  
  52. /* Set the corresponding bit in bytesVal.
  53. */
  54. bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));
  55. Serial.print(bytesVal, DEC);
  56.  
  57. lcd.setCursor(0, 1);
  58. // print the number of seconds since reset:
  59. lcd.print(bytesVal, DEC);
  60.  
  61. /* Pulse the Clock (rising edge shifts the next bit).
  62. */
  63. digitalWrite(inputclockPin, HIGH);
  64. delayMicroseconds(PULSE_WIDTH_USEC);
  65. digitalWrite(inputclockPin, LOW);
  66. }
  67.  
  68. return(bytesVal);
  69. }
  70.  
  71. /* Dump the list of zones along with their current status.
  72. */
  73. void display_pin_values()
  74. {
  75. Serial.print("Pin States:\r\n");
  76.  
  77. for(int i = 0; i < DATA_WIDTH; i++)
  78. {
  79. Serial.print(" Pin-");
  80. Serial.print(i);
  81. Serial.print(": ");
  82.  
  83. if((pinValues >> i) & 1)
  84. Serial.print("HIGH");
  85.  
  86. else
  87. Serial.print("LOW");
  88.  
  89. Serial.print("\r\n");
  90. }
  91.  
  92. Serial.print("\r\n");
  93. }
  94.  
  95.  
  96. void setup() {
  97. // set up the LCD's number of rows and columns:
  98. lcd.begin(16, 2);
  99. // Print a message to the LCD.
  100. lcd.print("ILZ-KOFFIE-01");
  101. pinMode(latchPin, OUTPUT);
  102. pinMode(dataPin, OUTPUT);
  103. pinMode(clockPin, OUTPUT);
  104. Serial.begin(9600);
  105. Serial.println("reset");
  106.  
  107. pinMode(ploadPin, OUTPUT);
  108. pinMode(inputdataPin, INPUT);
  109. pinMode(inputclockPin, OUTPUT);
  110.  
  111. digitalWrite(ploadPin, HIGH);
  112. pinValues = read_shift_regs();
  113. display_pin_values();
  114. oldPinValues = pinValues;
  115.  
  116. }
  117.  
  118. void loop() {
  119. // set the cursor to column 0, line 1
  120. // (note: line 1 is the second row, since counting begins with 0):
  121.  
  122.  
  123. // for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
  124. digitalWrite(latchPin, LOW);
  125.  
  126. int numberToDisplay = 254;
  127.  
  128. shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
  129. delay(200);
  130.  
  131. digitalWrite(latchPin, HIGH);
  132. delay(200);
  133. // update();
  134.  
  135. pinValues = read_shift_regs();
  136.  
  137. /* If there was a chage in state, display which ones changed.
  138. */
  139. if(pinValues != oldPinValues)
  140. {
  141. Serial.print("*Pin value change detected*\r\n");
  142. display_pin_values();
  143. oldPinValues = pinValues;
  144. }
  145.  
  146. delay(POLL_DELAY_MSEC);
  147. // }
  148. }
  149.  
  150. void update() {
  151. lcd.setCursor(0, 1);
  152. // print the number of seconds since reset:
  153. lcd.print(millis()/1000);
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement