Skip to content

Instantly share code, notes, and snippets.

@garethfoote
Created November 12, 2015 18:39
Show Gist options
  • Save garethfoote/fb3509d6d7bc5751dfad to your computer and use it in GitHub Desktop.
Save garethfoote/fb3509d6d7bc5751dfad to your computer and use it in GitHub Desktop.
int buttonPin = 2; // The number of the input pin for the button
int ledPin = 1; // The number of the output pin for the LED
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// Tell the Gemma that the LED pin is an output
pinMode(ledPin, OUTPUT);
// Tell the Gemma that the pushbutton pin Is an input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the pushbutton value.
// digitalRead() returns one of two values.
// If the button is pushed the reading will be HIGH (5V)
// If the button is released the reading wll be LOW (0V)
buttonState = digitalRead(buttonPin);
// If the pushbutton is pressed...
if (buttonState == HIGH) {
// ...turn the LED on.
digitalWrite(ledPin, HIGH);
}
else {
// ...turn the LED off.
digitalWrite(ledPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment