From 757deda43a2042962eb9670d5c4b6c8c3f3cb2dd Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 29 Dec 2013 22:17:48 -0500 Subject: [PATCH] Adding unreliable switch example --- arduino/UnreliableSwitch/Makefile | 1 + arduino/UnreliableSwitch/UnreliableSwitch.ino | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 120000 arduino/UnreliableSwitch/Makefile create mode 100644 arduino/UnreliableSwitch/UnreliableSwitch.ino diff --git a/arduino/UnreliableSwitch/Makefile b/arduino/UnreliableSwitch/Makefile new file mode 120000 index 0000000..51c7f30 --- /dev/null +++ b/arduino/UnreliableSwitch/Makefile @@ -0,0 +1 @@ +../arduino.mk \ No newline at end of file diff --git a/arduino/UnreliableSwitch/UnreliableSwitch.ino b/arduino/UnreliableSwitch/UnreliableSwitch.ino new file mode 100644 index 0000000..0a6d1f3 --- /dev/null +++ b/arduino/UnreliableSwitch/UnreliableSwitch.ino @@ -0,0 +1,21 @@ +const unsigned int BUTTON_PIN = 7; +const unsigned int LED_PIN = 13; + +int ledState = LOW; + +void setup() { + pinMode(LED_PIN, OUTPUT); + pinMode(BUTTON_PIN, INPUT); +} + +void loop() { + const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN); + + if (CURRENT_BUTTON_STATE == HIGH) { + ledState = HIGH; + } else { + ledState = LOW; + } + + digitalWrite(LED_PIN, ledState); +}