/*
Q) When X is pushed 3 times, light must be on. If it pushes another 3 times,
the light must be off. [POSITIVE TRANSITION]
*/
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(8, OUTPUT);
}
int count = 0;
bool ledState = 0;
void loop() {
if (digitalRead(2) == HIGH && ledState == 0) {
count = count + 1; // Increment the count variable by 1
ledState = 1; // Indicates that the LED is turned on
}
// Check if the button is not pressed
if (digitalRead(2) == LOW) {
ledState = 0; // Indicate the LED is turned off
}
// Check if the count variable is equal to 3
if (count == 3) {
digitalWrite(8, HIGH); // Turn on the LED
}
// Check if the count variable is equal to 6
if (count == 6) {
digitalWrite(8, LOW); // Turn off the LED
count = 0; // Reset the count variable to 0
}
}