Skip to content

Instantly share code, notes, and snippets.

@iotguider
Created July 25, 2017 15:29
Show Gist options
  • Save iotguider/3dbba3a5a32af3f2ae277b0a095ed881 to your computer and use it in GitHub Desktop.
Save iotguider/3dbba3a5a32af3f2ae277b0a095ed881 to your computer and use it in GitHub Desktop.
Code for LED with Pushbutton in Arduino
const int buttonPin = 6; //Number of Pushbutton Pin
const int ledPin = 13; //Number of LED Pin
int buttonState = 0; //Variable of Pushbutton Status
void setup() {
//Initialize LED Pin
pinMode(ledPin, OUTPUT);
//Initialize Pushbutton Pin
pinMode(buttonPin, INPUT);
}
void loop() {
//Read the Pushbutton state and Turn On or Off LED corresponding the state
if (digitalRead(buttonPin) == 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