Skip to content

Instantly share code, notes, and snippets.

@cowdinosaur
Last active August 29, 2015 14:06
Show Gist options
  • Save cowdinosaur/e66fcb699ca1ec4f6309 to your computer and use it in GitHub Desktop.
Save cowdinosaur/e66fcb699ca1ec4f6309 to your computer and use it in GitHub Desktop.
Tinkerbot 3.4: Reading the value of a switch to control an LED
const int LIMIT_SWITCH_PIN = 12;
const int LED_PIN = 13;
void setup() {
pinMode(LIMIT_SWITCH_PIN, INPUT);
digitalWrite(LIMIT_SWITCH_PIN,HIGH);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int switch_value = digitalRead(LIMIT_SWITCH_PIN);
if (switch_value == HIGH) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment