Skip to content

Instantly share code, notes, and snippets.

@SamoraMachel
Created February 14, 2023 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamoraMachel/e2de9311f51b767e90bdee9fba0a2c82 to your computer and use it in GitHub Desktop.
Save SamoraMachel/e2de9311f51b767e90bdee9fba0a2c82 to your computer and use it in GitHub Desktop.
int push_button = 8;
int light = 7;
String ledStatus = "off";
int counter = 0;
void setup() {
pinMode(push_button, INPUT_PULLUP);
pinMode(light, OUTPUT);
digitalWrite(light, LOW);
}
void loop() {
int buttonState = digitalRead(push_button);
if(buttonState == LOW) {
if(counter == 3) {
counter -= 3;
if (ledStatus == "off") {
ledStatus = "on";
digitalWrite(light, HIGH);
} else {
ledStatus = "off";
digitalWrite(light, LOW);
}
} else {
counter += 1;
}
}
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment