-
Notifications
You must be signed in to change notification settings - Fork 0
/
jeopardy_buttons.ino
114 lines (96 loc) · 2.59 KB
/
jeopardy_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
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
#define BTN_1_LIGHT_PIN 3
#define BTN_2_LIGHT_PIN 4
#define BTN_3_LIGHT_PIN 5
#define BTN_1_SWITCH_PIN 6
#define BTN_2_SWITCH_PIN 7
#define BTN_3_SWITCH_PIN 8
int pressedButton = 0;
unsigned long blinkStart;
int blinkButtonLightPin;
boolean disableButton1 = false;
boolean disableButton2 = false;
boolean disableButton3 = false;
void setup() {
Serial.begin(9600);
pinMode(BTN_1_LIGHT_PIN, OUTPUT);
pinMode(BTN_2_LIGHT_PIN, OUTPUT);
pinMode(BTN_3_LIGHT_PIN, OUTPUT);
pinMode(BTN_1_SWITCH_PIN, INPUT);
pinMode(BTN_2_SWITCH_PIN, INPUT);
pinMode(BTN_3_SWITCH_PIN, INPUT);
blinkButton(1, 2000);
blinkButton(2, 2000);
blinkButton(3, 2000);
}
void loop() {
if(Serial.available() > 0 && Serial.read() == 'g') {
pressedButton = 0;
if(digitalRead(BTN_1_SWITCH_PIN) == LOW) {
disableButton1 = true;
}
else {
digitalWrite(BTN_1_LIGHT_PIN, HIGH);
}
if(digitalRead(BTN_2_SWITCH_PIN) == LOW) {
disableButton2 = true;
}
else {
digitalWrite(BTN_2_LIGHT_PIN, HIGH);
}
if(digitalRead(BTN_3_SWITCH_PIN) == LOW) {
disableButton3 = true;
}
else {
digitalWrite(BTN_3_LIGHT_PIN, HIGH);
}
if(disableButton1 && disableButton2 && disableButton3) {
pressedButton = -1;
}
while(pressedButton == 0) {
if(digitalRead(BTN_1_SWITCH_PIN) == LOW && !disableButton1) {
pressedButton = 1;
digitalWrite(BTN_2_LIGHT_PIN, LOW);
digitalWrite(BTN_3_LIGHT_PIN, LOW);
}
else if(digitalRead(BTN_2_SWITCH_PIN) == LOW && !disableButton2) {
pressedButton = 2;
digitalWrite(BTN_1_LIGHT_PIN, LOW);
digitalWrite(BTN_3_LIGHT_PIN, LOW);
}
else if(digitalRead(BTN_3_SWITCH_PIN) == LOW && !disableButton3) {
pressedButton = 3;
digitalWrite(BTN_1_LIGHT_PIN, LOW);
digitalWrite(BTN_2_LIGHT_PIN, LOW);
}
delay(1);
}
Serial.println(pressedButton);
blinkButton(pressedButton, 3000);
disableButton1 = false;
disableButton2 = false;
disableButton3 = false;
}
}
void blinkButton(int button, int durationMillis) {
blinkStart = millis();
switch(button) {
case 1:
blinkButtonLightPin = BTN_1_LIGHT_PIN;
break;
case 2:
blinkButtonLightPin = BTN_2_LIGHT_PIN;
break;
case 3:
blinkButtonLightPin = BTN_3_LIGHT_PIN;
break;
default:
durationMillis = 0;
}
while( (millis() - blinkStart) < durationMillis) {
digitalWrite(blinkButtonLightPin, LOW);
delay(100);
digitalWrite(blinkButtonLightPin, HIGH);
delay(100);
}
digitalWrite(blinkButtonLightPin, LOW);
}