Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x3F, 16, 2);
- //Pin verbunden mit SH_CP des 74HC595
- int shiftPin = 8;
- //Pin verbunden mit ST_CP des 74HC595
- int storePin = 9;
- //Pin verbunden mit DS des 74HC595
- int dataPin = 10;
- int counter = 1;
- int anzeige = 1;
- int storage = 0;
- boolean lastPressed = false;
- boolean lastPressed2 = false;
- boolean lastPressed3 = false;
- void setup() {
- lcd.begin();
- lcd.backlight();
- pinMode(storePin, OUTPUT);
- pinMode(shiftPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(2, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(4, INPUT_PULLUP);
- lcd.print("Relay:");
- Serial.begin(9600);
- shiftOut(dataPin, shiftPin, MSBFIRST, ~storage);
- digitalWrite(storePin, HIGH);
- }
- void loop() {
- boolean pressed = digitalRead(2) == LOW;
- boolean pressed2 = digitalRead(3) == LOW;
- boolean pressed3 = digitalRead(4) == LOW;
- digitalWrite(storePin, LOW);
- lcd.setCursor(0, 1);
- lcd.print(anzeige);
- lcd.print(" ");
- lcd.print((storage & counter) == 0 ?"Aus ": "An ");
- if (pressed && !lastPressed) {
- counter = counter * 2;
- anzeige = anzeige + 1;
- } else if (pressed2 && !lastPressed2) {
- counter = counter / 2;
- anzeige = anzeige - 1;
- }
- if (counter > 128) {
- counter = 1;
- anzeige = 1;
- } else if (counter < 1) {
- counter = 128;
- anzeige = 8;
- }
- if (!lastPressed3 && pressed3) {
- Serial.print("Storage");
- Serial.println(storage);
- Serial.print("Counter");
- Serial.println(counter);
- if ((storage & counter) == 0) {
- Serial.println("a");
- shiftOut(dataPin, shiftPin, MSBFIRST, ~(storage | counter));
- digitalWrite(storePin, HIGH);
- storage |= counter;
- } else {
- storage &= ~counter;
- Serial.println("b");
- shiftOut(dataPin, shiftPin, MSBFIRST, ~storage);
- digitalWrite(storePin, HIGH);
- }
- }
- lastPressed = pressed;
- lastPressed2 = pressed2;
- lastPressed3 = pressed3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement