Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Created April 8, 2016 02:29
Show Gist options
  • Save shawngrimes/2f609c07d9a67ccf7d7e63b2c386e189 to your computer and use it in GitHub Desktop.
Save shawngrimes/2f609c07d9a67ccf7d7e63b2c386e189 to your computer and use it in GitHub Desktop.
Basic sketch demonstrating a digitalInput with a button
int ledPin=13; //Variable to store pin of LED
int buttonPin=3; //Variable to store pin of button
int buttonValue=0; //Variable to store last known value of button state
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); //Setup LED pin for output
pinMode(buttonPin, INPUT); //Setup button pin for input
}
void loop() {
// put your main code here, to run repeatedly:
buttonValue=digitalRead(buttonPin); //Read the value of the button pin
if(buttonValue==HIGH){ //if the button is open (not pressed)
digitalWrite(ledPin,LOW); //turn the LED off
}else{ //otherwise, if the button is closed (pressed)
digitalWrite(ledPin,HIGH); //turn the LED on
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment