#define buttonPin 6
#define LedPin 11
bool Pomocnahodnota0=0;
bool buttonState=0;
bool lastButtonState=0;
bool LedState=0;
unsigned long lastDebounceTime=0;
unsigned long BeforeTime=0; //pre ledku
int debounceDelay=50;
int Interval = 1000;
int PomocnaHodnota3=0; //pre vypis poctu stlaceni
void setup() {
pinMode(LedPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
bool reading = digitalRead(buttonPin);
if (reading != lastButtonState)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
if (reading != buttonState)
{
buttonState = reading;
if (buttonState == HIGH)
{
PomocnaHodnota3=PomocnaHodnota3+1;
Serial.println("tlacidlo bolo stlacene "+String(PomocnaHodnota3)+"-krát");
Pomocnahodnota0=!Pomocnahodnota0;
}
}
}
if(Pomocnahodnota0==1)
{
if(millis()-BeforeTime>=Interval)
{
BeforeTime =millis();
LedState=!LedState;
digitalWrite(LedPin,LedState);
}
}
else
digitalWrite(LedPin,0);
lastButtonState = reading;
}