const byte greenLedPin = 8;
const byte buttonPin = 7;
bool buttonState;
bool state = LOW;
bool greenLedState;
int counter = 0;
void setup() {
pinMode(greenLedPin, OUTPUT );
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
counter++;
}
else if (counter >= 5 && buttonState == LOW) {
state = !state;
counter = 0;
}
if (state == LOW) {
digitalWrite(greenLedPin, HIGH);
} else {
digitalWrite(greenLedPin, LOW);
}
}