summaryrefslogtreecommitdiff
path: root/src/gpio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpio.cpp')
-rw-r--r--src/gpio.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/gpio.cpp b/src/gpio.cpp
new file mode 100644
index 0000000..d7dcd7b
--- /dev/null
+++ b/src/gpio.cpp
@@ -0,0 +1,35 @@
+#include "badge/gpio.h"
+
+#include <Arduino.h>
+
+#define BUTTON_PIN 0
+
+static unsigned long pressedTime = 0;
+static unsigned long releasedTime = 0;
+
+void de::uvok::badge::gpio_init(void)
+{
+}
+
+long de::uvok::badge::gpio_poll(void)
+{
+ static int lastState = HIGH;
+ int buttonState = digitalRead(BUTTON_PIN);
+ long pressDuration = 0;
+ if (lastState == HIGH && buttonState == LOW)
+ {
+ Serial.println("``\\__");
+ pressedTime = millis();
+ lastState = LOW;
+ }
+ else if (lastState == LOW && buttonState == HIGH)
+ {
+ lastState = HIGH;
+ Serial.println("__/``");
+ releasedTime = millis();
+
+ pressDuration = releasedTime - pressedTime;
+ };
+
+ return pressDuration;
+}