blob: d7dcd7b996e55d699f4ea4ef6223a59bcb4bc61c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}
|