Skip to content

Instantly share code, notes, and snippets.

@jessherzog
Created September 24, 2015 20:06
Show Gist options
  • Save jessherzog/1bbdb1bb0facc052f338 to your computer and use it in GitHub Desktop.
Save jessherzog/1bbdb1bb0facc052f338 to your computer and use it in GitHub Desktop.
button pressed, led stays on or off
const int buttonPin = 7;
const int ledPin = 11;
int ledState = LOW;
int buttonState = 0;
boolean pressed = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && pressed == false ) {
// turn LED on:
if (ledState == LOW) {
ledState = HIGH;
}
else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment