-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompetition_buzzer.ino
More file actions
88 lines (72 loc) · 1.51 KB
/
competition_buzzer.ino
File metadata and controls
88 lines (72 loc) · 1.51 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
int state;
int p1Light = 10;
int p2Light = 11;
int p1Button = 2;
int p2Button = 3;
int buzzerPin = 6;
void outOfTime() {
tone(buzzerPin,1200);
delay(500);
noTone(buzzerPin);
}
void triggerMusic() {
for (int i=0;i<4;i++) {
tone(buzzerPin,1000);
delay(50);
noTone(buzzerPin);
delay(50);
}
tone(buzzerPin,2000);
delay(250);
noTone(buzzerPin);
}
void setup() {
// put your setup code here, to run once:
pinMode(p1Light,OUTPUT);
pinMode(p2Light,OUTPUT);
pinMode(p1Button, INPUT);
pinMode(p2Button, INPUT);
attachInterrupt(digitalPinToInterrupt(p1Button), blink1, FALLING);
attachInterrupt(digitalPinToInterrupt(p2Button), blink2, FALLING);
state = 0;
}
void blink1(){
state = 1;
}
void blink2(){
state = 2;
}
void buzzHelper(int pin) {
for (int i = 0; i < 10;i++) {
digitalWrite(pin,LOW);
tone(buzzerPin,1000);
delay(10);
digitalWrite(pin,HIGH);
noTone(buzzerPin);
delay(10);
}
triggerMusic();
for (int i = 0; i < 6;i++) {
digitalWrite(pin,LOW);
delay(100);
digitalWrite(pin,HIGH);
delay(750);
}
}
void loop() {
// put your main code here, to run repeatedly:
if (state==0) {
digitalWrite(p2Light,LOW);
digitalWrite(p1Light,LOW);
}
else if (state == 1) {
buzzHelper(p1Light);
outOfTime();
state = 0;
}
else if (state == 2) {
buzzHelper(p2Light);
outOfTime();
state = 0;
}
}