From a5571a834f1b2b7ec0b8cdc016884442099ceab8 Mon Sep 17 00:00:00 2001 From: uvok Date: Thu, 17 Jul 2025 21:33:50 +0200 Subject: Reorganize, scope, add GPIO --- src/gpio.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/gpio.cpp (limited to 'src/gpio.cpp') 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 + +#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; +} -- cgit v1.2.3