Skip to content

Instantly share code, notes, and snippets.

@SLOLNE
Created January 19, 2016 19:48
Show Gist options
  • Save SLOLNE/3ab2a5a904d93f42a6ca to your computer and use it in GitHub Desktop.
Save SLOLNE/3ab2a5a904d93f42a6ca to your computer and use it in GitHub Desktop.
Button Pressed
// Turn on LED while the button is pressed
//Camille Kauffman
//excercise 4-2 from Getting Started with Arduino
const int LED = 13; //the pin for the light
const int BUTTON = 7;//the input pin hwere the pushbutton is connected
int val = 0; //val will be used to store the state of the input pin
void setup() {
pinMode(LED, OUTPUT); //tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}
void loop() {
val = digitalRead(BUTTON); //read input value and store it
//check whether the input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); //turn LED on
} else {
digitalWrite(LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment