Skip to content

Instantly share code, notes, and snippets.

@runemadsen
Last active October 2, 2017 05:42
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 runemadsen/8d92bf788f648ed1c28d9767d241ad09 to your computer and use it in GitHub Desktop.
Save runemadsen/8d92bf788f648ed1c28d9767d241ad09 to your computer and use it in GitHub Desktop.
boolean ledState = false;
int lastButtonState = 0;
void setup() {
pinMode(4, INPUT);
pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop() {
int buttonState = digitalRead(4);
if (lastButtonState != buttonState && buttonState == 1) {
ledState = !ledState;
}
lastButtonState = buttonState;
if (ledState) {
digitalWrite(7,HIGH);
} else {
digitalWrite(7,LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment