#include <LiquidCrystal.h>
#include <Bounce2.h>
#define btnRed 7
#define btnGreen 6
#define btnBlu 5
#define interrupt 2
int stevec;
#define ledPin 3
Bounce2::Button tipka1, tipka2, tipka3 = Bounce2::Button();
int lastTime;
int delayTime = 150;
volatile bool state = LOW;
bool prevstate = state;
LiquidCrystal lcd(13,12,11,10,9,8);
int buttonPins[3] = {1,2,3};
void setup(){
pinMode(btnRed, INPUT_PULLUP);
pinMode(btnGreen, INPUT_PULLUP);
pinMode(btnBlu, INPUT_PULLUP);
tipka1.attach(btnRed, INPUT_PULLUP);
tipka1.interval(10);
tipka2.attach(btnGreen, INPUT_PULLUP);
tipka2.interval(10);
tipka3.attach(btnBlu, INPUT_PULLUP);
tipka3.interval(10);
Serial.begin(115200);
pinMode(interrupt, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interrupt), ISR_button, CHANGE);
}
void loop(){
if((millis()- lastTime) > delayTime){
tipka1.update();
tipka2.update();
tipka3.update();
lcd.setCursor(0,0);
lcd.print(stevec);
if (tipka1.pressed()){
stevec++;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
if (tipka2.pressed()){
stevec--;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
if (tipka3.pressed()){
stevec = 0;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
if (state != prevstate && ((millis()- lastTime) >delayTime)){
prevstate = state;
digitalWrite(ledPin, state);
lastTime = millis();
}
}
}
void ISR_button(){
state = !state;
lastTime = millis();
}