-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.ino
74 lines (63 loc) · 1.69 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
void setup_buttons(void) {
pinMode(4, OUTPUT);
pinMode(5, OUTPUT); //beep
pinMode(7, INPUT);
//pinMode(2, OUTPUT);
//digitalWrite(2, HIGH); // ethernet module on
pinMode(buttonPinUp, INPUT);//up
pinMode(buttonPinDown, INPUT);// down
pinMode(buttonPinEnter, INPUT);//enter
pinMode(buttonPinBack, INPUT);//back
}
int button_up() {
buttonStateUp = digitalRead(buttonPinUp);
if (buttonStateUp != lastButtonStateUp) {
// if the state has changed, increment the counter
if (buttonStateUp == HIGH) {
return 1;
}
// Delay a little bit to avoid bouncing
delay(50);
}
return 0;
lastButtonStateUp = buttonStateUp;
}
int button_down() {
buttonStateDown = digitalRead(buttonPinDown);
if (buttonStateDown != lastButtonStateDown) {
// if the state has changed, increment the counter
if (buttonStateDown == HIGH) {
return 1;
}
// Delay a little bit to avoid bouncing
delay(50);
}
return 0;
lastButtonStateDown = buttonStateDown;
}
int button_enter() {
buttonStateEnter = digitalRead(buttonPinBack);
if (buttonStateEnter != lastButtonStateEnter) {
// if the state has changed, increment the counter
if (buttonStateEnter == HIGH) {
return 1;
}
// Delay a little bit to avoid bouncing
delay(50);
}
return 0;
lastButtonStateEnter = buttonStateEnter;
}
int button_back() {
buttonStateDown = digitalRead(buttonPinDown);
if (buttonStateBack != lastButtonStateBack) {
// if the state has changed, increment the counter
if (buttonStateBack == HIGH) {
return 1;
}
// Delay a little bit to avoid bouncing
delay(50);
}
return 0;
lastButtonStateBack = buttonStateBack;
}