Skip to content

Instantly share code, notes, and snippets.

@garethfoote
Created January 26, 2018 14:40
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 garethfoote/cf3d5724bac58369395e966b0b43042e to your computer and use it in GitHub Desktop.
Save garethfoote/cf3d5724bac58369395e966b0b43042e to your computer and use it in GitHub Desktop.
// Make variables for the led, button pin number and delay
// These can be used throughout your code
int ledPin = 13;
int buttonPin = 7;
int delayMs = 250;
void setup() {
// Tell pin 13 to work as an OUTPUT
pinMode( ledPin, OUTPUT );
// Tell pin 7 to work as an INPUT
pinMode( buttonPin, INPUT_PULLUP );
}
void loop() {
// Capture the current state of the button.
int buttonState = digitalRead(buttonPin);
// If the buttonState variable is LOW
// (i.e. the button is pressed)
if ( buttonState == LOW ) {
// We blink our LED
digitalWrite( ledPin, HIGH );
delay(delayMs);
digitalWrite( ledPin, LOW );
delay(delayMs);
} else {
// else we 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