LED a tlacitka CZ
Pavel1TU
c_cpp
2 years ago
1.3 kB
6
Indexable
//IO #define BTN1 2 //tlacitko 1 na vstup 2 #define BTN2 3 //tlacitko 2 na vstup 3 bool presentButton1, presentButton2; //aktualni stav tlacitek bool lastButton1, lastButton2; //posledni stav tlacitek bool edgeButton1, edgeButton1; //nabezna hrana tlacitek bool LEDstatus; void setup() { //IO //internal pull-up pinMode(BTN1, INPUT_PULLUP); pinMode(BTN2, INPUT_PULLUP); pinMode(LED_BUILTIN, OUTPUT); } void loop() { //ulozeni aktualniho stavu tlacitek (negace protoze je pouzit PULUP) presentButton1 = !digitalRead(BTN1); presentButton2 = !digitalRead(BTN2); //detekce nabezne hrany po stisku tlacitka edgeButton1 = (presentButton1 ^ lastButton1) & !presentButton1; edgeButton2 = (presentButton2 ^ lastButton2) & !presentButton2; if (edgeButton1 && LEDstatus == 0) { digitalWrite(LED_BUILTIN, HIGH); LEDstatus = 1; } if (edgeButton2 && LEDstatus == 0) { digitalWrite(LED_BUILTIN, HIGH); LEDstatus = 1; } if (LEDstatus == 1) { delay(2000); digitalWrite(LED_BUILTIN, LOW); LEDstatus = 0; } lastButton1 = presentButton1; //ulozeni aktualniho stavu tlacitka jako posledni stav (musi byt na konci LOOP) lastButton2 = presentButton2; //ulozeni aktualniho stavu tlacitka jako posledni stav }
Editor is loading...