Skip to content

Instantly share code, notes, and snippets.

@Sugeevan
Created April 22, 2016 14:51
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 Sugeevan/4173ceedfe79be117430865de052b8b8 to your computer and use it in GitHub Desktop.
Save Sugeevan/4173ceedfe79be117430865de052b8b8 to your computer and use it in GitHub Desktop.
// Turn on LED while the button is pressed
const int LED = 13; // the pin for the LED
const int BUTTON = 7; // pushbutton is connected
int val = 0; // store input state
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