Skip to content

Instantly share code, notes, and snippets.

@peow2373
Last active February 10, 2020 19:41
Show Gist options
  • Save peow2373/1f25bb2967656972711800d055654182 to your computer and use it in GitHub Desktop.
Save peow2373/1f25bb2967656972711800d055654182 to your computer and use it in GitHub Desktop.
Reads a digital input from a button on pin 2 and turns on two LEDs in series when the button is pressed
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the Serial Monitor
http://www.arduino.cc/en/Tutorial/DigitalReadSerial
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
int ledPin = 5;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(pushButton, INPUT);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
if (digitalRead(pushButton) == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment