const int ledPin = 8;
const int buttonPin = 4;
int pressCount = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
static bool buttonPressed = false;
static unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 500;
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW && !buttonPressed && (millis() - lastDebounceTime > debounceDelay)) {
buttonPressed = true;
lastDebounceTime = millis();
pressCount++;
Serial.print("Button is pressed, press count: ");
Serial.println(pressCount);
if (pressCount == 3) {
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
delay(2000);
digitalWrite(ledPin, LOW);
pressCount = 0;
}
}
if (buttonState == HIGH && buttonPressed) {
buttonPressed = false;
}
}