-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_roulette_game.ino
61 lines (40 loc) · 976 Bytes
/
led_roulette_game.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
// Change component pins for your own
#define LED_1 13
#define LED_2 12
#define LED_3 10
#define LED_4 8
#define LED_5 9
#define LED_6 11
#define BUTTON 2
#define BUZZER 7
#define WINNER_LED LED_3
#define LED_AMOUNT 6
int leds[LED_AMOUNT] = {LED_1, LED_2, LED_3, LED_4, LED_5, LED_6};
#define BUZZER_TIME 200
int time_on = 1000;
unsigned long turned_on;
void setup() {
pinMode(BOTON, INPUT_PULLUP);
for(int i = 0; i < LED_CANT; i++) pinMode(leds[i], OUTPUT);
pinMode(BUZZER, OUTPUT);
}
void check_button(int on_led){
if(!digitalRead(BUTTON)){
if(on_led == WINNER_LED){
time_on -= 100;
digitalWrite(BUZZER, HIGH);
delay(BUZZER_TIME);
digitalWrite(BUZZER, LOW);
}
}
}
void loop() {
for(int i = 0; i < LED_AMOUNT; i++){
turned_on = millis();
while(turned_on + time_on > millis()){
digitalWrite(leds[i], HIGH);
check_button(leds[i]);
}
digitalWrite(leds[i], LOW);
}
}