Skip to content

Instantly share code, notes, and snippets.

@scottferg
Created September 16, 2009 14:13
Show Gist options
  • Save scottferg/188062 to your computer and use it in GitHub Desktop.
Save scottferg/188062 to your computer and use it in GitHub Desktop.
const int buttonPin = 2; // Number of the pushbutton pin
const int ledPin = 13; // Number of the LED pin
int buttonState = 0;
int lightOn = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
lightOn = !lightOn;
if (lightOn) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment