-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathButtons.cpp
71 lines (62 loc) · 1.72 KB
/
Buttons.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
©LPD Lawrence Link 2021
All rights reserved
Geiger Counter N1
Licensed under GNU General Public License v3.0
-------CONTACT AT-------
Lawrence-Link@outlook.com
*/
#include "global.h"
#include "Buttons.h"
#include <Arduino.h>
enum {Short, Long} PIN_BUTTON_OK_STATE;
bool buttonActiveOK = false; //needed to been accessable in the main loop
bool longPressActive = false;
#define longPressTime 200
void buttons_init() {
pinMode(PIN_BUTTON_UP, INPUT_PULLUP);
pinMode(PIN_BUTTON_OK, INPUT_PULLUP);
pinMode(PIN_BUTTON_DN, INPUT_PULLUP);
}
buttonReturnDef refresh_button() {
static long buttonTimer = 0;
buttonReturnDef _buf;
static bool buttonActiveUP = false;
static bool buttonActiveDN = false;
if (digitalRead(PIN_BUTTON_UP) == LOW){
buttonActiveUP = true;
}else if (digitalRead(PIN_BUTTON_UP) == HIGH && buttonActiveUP == true){
buttonActiveUP = false;
_buf = UPPER;
}
else if (digitalRead(PIN_BUTTON_DN) == LOW){
buttonActiveDN = true;
}else if (digitalRead(PIN_BUTTON_DN) == HIGH && buttonActiveDN == true){
buttonActiveDN = false;
_buf = LOWER;
}
else if (digitalRead(PIN_BUTTON_OK) == LOW) {
if (buttonActiveOK == false) {
buttonActiveOK = true;
buttonTimer = millis();
}
if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {
longPressActive = true;
// Long press
_buf = MID_LONG;
}
} else if(digitalRead(PIN_BUTTON_OK) == HIGH) {
if (buttonActiveOK == true) {
if (longPressActive == true) {
longPressActive = false;
} else {
// short_press
_buf = MID_SHORT;
}
buttonActiveOK = false;
}
}else {
_buf = NONE;
}
return _buf;
}