-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButtons.ino
81 lines (65 loc) · 1.53 KB
/
Buttons.ino
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
/**************************************************
* class: Buttons
* constructor: initLcd()
*
* methods:
**************************************************/
//up .O...
//down O....
//left ....O
//right ...O.
//enter ..O..
#define NUM_OF_BUTTONS 5
#include "Constants.h"
void initButtons() {
pinMode(BUTTONS_INPUT_PIN, INPUT);
pinMode(BUTTONS_A_PIN, OUTPUT);
pinMode(BUTTONS_B_PIN, OUTPUT);
pinMode(BUTTONS_C_PIN, OUTPUT);
}
void callButton(char buttonNumber, boolean isPressed) {
static unsigned char lastPress[NUM_OF_BUTTONS];
if (buttonFilter(isPressed, &(lastPress[buttonNumber]))) { return; }
switch(buttonNumber) {
case 0:
downPressed(isPressed);
break;
case 1:
upPressed(isPressed);
break;
case 2:
enterPressed(isPressed);
break;
case 3:
rightPressed(isPressed);
break;
case 4:
leftPressed(isPressed);
break;
}
}
void buttons() {
boolean isPressed;
for(char n = 0; n != NUM_OF_BUTTONS; n++) {
digitalWrite(BUTTONS_A_PIN, bitRead(n, 0));
digitalWrite(BUTTONS_B_PIN, bitRead(n, 1));
digitalWrite(BUTTONS_C_PIN, bitRead(n, 2));
isPressed = digitalRead(BUTTONS_INPUT_PIN);
if (isPressed) {
Global.lastUserInteraction = now();
}
callButton(n, isPressed);
}
}
boolean buttonFilter(boolean isPressed, unsigned char *lastPress) {
if (!isPressed) {
*lastPress = 0;
return true;
}
if (*lastPress > 0) {
(*lastPress)--;
return true;
}
*lastPress = 1000/BUTTONS_SPEED/PROGRAM_SPEED;
return false;
}