int led = 13;
#define button 8
byte value;
int count = 0;
int buttonpress = 0;
bool ledON = false;
void setup () {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
digitalWrite(led, LOW);
buttonpress = digitalRead(button);
Serial.print("Button is not pressed Value is: ");
Serial.println(buttonpress);
}
void loop(){
value = digitalRead(button);
if(buttonpress != value){
if(value == LOW){
count++;
delay(1000);
Serial.print("Button pressed count: ");
Serial.println(count);
if(!ledON && count == 3) {
delay(200);
digitalWrite(led, HIGH);
Serial.println("Button Pressed 3 times, LED IS ON");
ledON = true;
count = 0;
}
}
}
if (ledON && count>=3){
delay(200);
digitalWrite(led, LOW);
Serial.println("Button Pressed 3 times, LED IS OFF");
count= 0;
ledON = false;
}
}