-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytest.ino
More file actions
127 lines (98 loc) · 2.61 KB
/
Copy pathmytest.ino
File metadata and controls
127 lines (98 loc) · 2.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <ADK.h>
#define BTN_SLIDER_0 0x00
#define BTN_SLIDER_1 0x01
#define BTN_SLIDER_2 0x02
#define BTN_MASK_PRESS 0x8000
#define BTN_MASK_HOLD 0x4000
#define BTN_MASK_RELEASE 0x2000
#define BTN_MASK_ID 0x003F
#define BTN_INITIAL_DELAY 10 //10ms before a click registers
#define BTN_HOLD_DELAY 400 //400mas before a click becomes a hold
#define BTN_AUTOREPEAT 100 //auto-repeat every 100ms
ADK L;
static uint8_t ledrgb[6][3]={
0,0,255,
255,0,0,
255,255,0,
0,0,255,
0,255,0,
255,0,0
};
String string[3]={
"Google","is","GOD"};
static int slider=100;
static uint16_t btnProcess(){
static uint64_t lastActionTime[32] = {
0, };
static uint32_t clickSent = 0;
static uint32_t holdSent = 0;
static uint32_t lastStates = 0;
uint32_t curState, t, i, mask;
curState = (((uint32_t)L.capSenseButtons()) << 16) | L.capSenseIcons();
t = lastStates ^ curState;
lastStates = curState;
//update states for all buttons
for(mask = 1, i = 0; i < 32; i++, mask <<= 1) if(t & mask){
lastActionTime[i] = L.getUptime();
}
for(mask = 1, i = 0; i < 32; i++, mask <<= 1){
if(curState & mask){
uint64_t time = L.getUptime();
uint64_t lapsed = time - lastActionTime[i];
if(holdSent & mask){
if(lapsed > BTN_AUTOREPEAT){
lastActionTime[i] = time;
return i | BTN_MASK_HOLD;
}
}
else if(clickSent & mask){
if(lapsed > BTN_HOLD_DELAY){
holdSent |= mask;
lastActionTime[i] = time;
return i | BTN_MASK_HOLD;
}
}
else{ //maybe time to click
if(lapsed > BTN_INITIAL_DELAY){
clickSent |= mask;
lastActionTime[i] = time;
return i | BTN_MASK_PRESS;
}
}
}
else if(clickSent & mask){ //release
clickSent &=~ mask;
holdSent &=~ mask;
return i | BTN_MASK_RELEASE;
}
}
return 0;
}
void adkPutchar(char c){
Serial.write(c);
}
extern "C" void dbgPrintf(const char *, ... );
void setup(void)
{
Serial.begin(115200);
L.adkSetPutchar(adkPutchar);
L.adkInit();
}
void loop(){
uint8_t slider = L.capSenseSlider();
slider = (((uint32_t)slider) >> 3) + 16;
uint16_t button = btnProcess();
dbgPrintf("ADK: Value of Slider:%d\n",slider);
L.adkEventProcess();
for(int j=0;j<3;j++){
for(int i=0;i<6;i++){
L.ledDrawLetter(i,string[j].charAt(i),ledrgb[i][0],ledrgb[i][1],ledrgb[i][2]);
delay(slider);
}
delay(slider);
for(int x=0;x<6;x++){
L.ledDrawLetter(x,' ',0,0, 0);
delay(slider);
}
}
}