Skip to content

Instantly share code, notes, and snippets.

@hrysd
Created July 6, 2016 11:30
Show Gist options
  • Save hrysd/dc237f50bf5ffa7533fca094c803a5d8 to your computer and use it in GitHub Desktop.
Save hrysd/dc237f50bf5ffa7533fca094c803a5d8 to your computer and use it in GitHub Desktop.
const int LED = 13;
const int BUTTON = 7;
int val = 0;
int old_val = 0;
int state = 0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop() {
val = digitalRead(BUTTON);
if ((val == HIGH) && (old_val == LOW)) {
state = 1 - state;
delay(50);
}
old_val = val;
if (state == 1) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment