Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gallaugher/9894fdfb826fece2e034767f9aedb8e0 to your computer and use it in GitHub Desktop.
Save gallaugher/9894fdfb826fece2e034767f9aedb8e0 to your computer and use it in GitHub Desktop.
TXPlore Day 12, Learning By Doing 5 - BONUS Switch Case
byte BUTTON_PIN = 7;
byte LED_PIN = 6;
byte buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
switch (digitalRead(BUTTON_PIN)) {
case HIGH:
digitalWrite(LED_PIN, HIGH);
break;
case LOW:
digitalWrite(LED_PIN, LOW);
break;
default:
// shouldn't be here
Serial.println("ERROR: BUTTON_PIN was neither high nor low");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment