#include <Bounce2.h>
#define btnRed 5
#define btnGreen 4
#define btnBlue 3
#define btnYellow 2
int stevec;
Bounce2::Button tipka1, tipka2, tipka3, tipka4 = Bounce2::Button();
volatile byte stanje = LOW;
volatile bool m;
unsigned long timePass;
int timeDelay = 500;
int ledPin = 8;
void setup() {
tipka1.attach(btnRed, INPUT_PULLUP);
tipka2.attach(btnGreen, INPUT_PULLUP);
tipka3.attach(btnBlue, INPUT_PULLUP);
tipka1.interval(10);
tipka2.interval(10);
tipka3.interval(10);
tipka1.setPressedState(LOW);
tipka2.setPressedState(LOW);
tipka3.setPressedState(LOW);
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(btnYellow, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(btnYellow), ISR_prekinitev, FALLING);
}
void loop() {
tipka1.update();
tipka2.update();
tipka3.update();
if(tipka1.pressed()){
stevec++;
Serial.println(stevec);
}
if(tipka2.pressed()){
stevec--;
Serial.println(stevec);
}
if(tipka3.pressed()){
stevec = 0;
Serial.println(stevec);
}
if (stanje == HIGH && ((millis() - timePass) > timeDelay)){
digitalWrite(ledPin,stanje);
stanje = LOW;
timePass = millis();
}
}
void ISR_prekinitev(){
stanje = HIGH;
}