-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtons.cpp
More file actions
63 lines (40 loc) · 1.62 KB
/
Buttons.cpp
File metadata and controls
63 lines (40 loc) · 1.62 KB
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
// Buttons.cpp
#include "Buttons.h"
#define BOUNCE_TIME_BUTTON 600 // bounce time in ms for the menu button;
#define CapThreshold 100
CapSense but_1 = CapSense(8,9); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapSense but_2 = CapSense(8,10); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapSense but_3 = CapSense(8,11); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
void (*buttonCallback)(ButtonType) = NULL;
//*********************************************************************************************************
void checkButtons()
{
// last time the respective button was pressed; used for debouncing;
static unsigned long timeBtnMenu;
static unsigned long timeBtnSet;
static unsigned long timeBtnPlus;
if (but_1.capSense(30) > CapThreshold)
{
if (abs(millis() - timeBtnMenu) < BOUNCE_TIME_BUTTON) return;
if(buttonCallback != NULL)
buttonCallback(BUTTON_MENU);
timeBtnMenu = millis();
}
if (but_2.capSense(30) > CapThreshold)
{
// debouncing;
if (abs(millis() - timeBtnSet) < BOUNCE_TIME_BUTTON) return;
if(buttonCallback != NULL)
buttonCallback(BUTTON_SET);
timeBtnSet = millis();
}
if (but_3.capSense(30) > CapThreshold)
{
// debouncing;
if (abs(millis() - timeBtnPlus) < BOUNCE_TIME_BUTTON) return;
if(buttonCallback != NULL)
buttonCallback(BUTTON_PLUS);
timeBtnPlus = millis();
}
}
//*********************************************************************************************************