Skip to content

Instantly share code, notes, and snippets.

@jonathanprozzi
Created July 20, 2016 13:07
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 jonathanprozzi/cf8b7669e5653bc1a630e5d2c1ba99e1 to your computer and use it in GitHub Desktop.
Save jonathanprozzi/cf8b7669e5653bc1a630e5d2c1ba99e1 to your computer and use it in GitHub Desktop.
This is the basic code for controlling a LED with a pushbutton.
int ledPin = 13;
int buttonPin = 7;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(buttonPin, INPUT); // sets the digital pin 7 as input
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment