Advertisement
Guest User

Cool

a guest
Mar 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x3F, 16, 2);
  5. //Pin verbunden mit SH_CP des 74HC595
  6. int shiftPin = 8;
  7. //Pin verbunden mit ST_CP des 74HC595
  8. int storePin = 9;
  9. //Pin verbunden mit DS des 74HC595
  10. int dataPin = 10;
  11.  
  12. int counter = 1;
  13.  
  14. int anzeige = 1;
  15.  
  16. int storage = 0;
  17.  
  18. boolean lastPressed = false;
  19.  
  20. boolean lastPressed2 = false;
  21.  
  22. boolean lastPressed3 = false;
  23.  
  24. void setup() {
  25. lcd.begin();
  26. lcd.backlight();
  27.  
  28. pinMode(storePin, OUTPUT);
  29. pinMode(shiftPin, OUTPUT);
  30. pinMode(dataPin, OUTPUT);
  31. pinMode(2, INPUT_PULLUP);
  32. pinMode(3, INPUT_PULLUP);
  33. pinMode(4, INPUT_PULLUP);
  34.  
  35. lcd.print("Relay:");
  36.  
  37. Serial.begin(9600);
  38.  
  39. shiftOut(dataPin, shiftPin, MSBFIRST, ~storage);
  40. digitalWrite(storePin, HIGH);
  41. }
  42.  
  43. void loop() {
  44. boolean pressed = digitalRead(2) == LOW;
  45. boolean pressed2 = digitalRead(3) == LOW;
  46. boolean pressed3 = digitalRead(4) == LOW;
  47.  
  48. digitalWrite(storePin, LOW);
  49.  
  50. lcd.setCursor(0, 1);
  51. lcd.print(anzeige);
  52. lcd.print(" ");
  53. lcd.print((storage & counter) == 0 ?"Aus ": "An ");
  54.  
  55. if (pressed && !lastPressed) {
  56. counter = counter * 2;
  57. anzeige = anzeige + 1;
  58. } else if (pressed2 && !lastPressed2) {
  59. counter = counter / 2;
  60. anzeige = anzeige - 1;
  61. }
  62.  
  63. if (counter > 128) {
  64. counter = 1;
  65. anzeige = 1;
  66. } else if (counter < 1) {
  67. counter = 128;
  68. anzeige = 8;
  69. }
  70.  
  71. if (!lastPressed3 && pressed3) {
  72. Serial.print("Storage");
  73. Serial.println(storage);
  74. Serial.print("Counter");
  75. Serial.println(counter);
  76. if ((storage & counter) == 0) {
  77. Serial.println("a");
  78. shiftOut(dataPin, shiftPin, MSBFIRST, ~(storage | counter));
  79. digitalWrite(storePin, HIGH);
  80. storage |= counter;
  81. } else {
  82. storage &= ~counter;
  83. Serial.println("b");
  84. shiftOut(dataPin, shiftPin, MSBFIRST, ~storage);
  85. digitalWrite(storePin, HIGH);
  86. }
  87. }
  88.  
  89. lastPressed = pressed;
  90. lastPressed2 = pressed2;
  91. lastPressed3 = pressed3;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement