-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuzzer.cpp
67 lines (61 loc) · 1.1 KB
/
Buzzer.cpp
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
#include "Buzzer.h"
Buzzer::Buzzer(byte pin) {
this->pin = pin;
this->prev_status = Low;
init();
}
void Buzzer::toMid() {
tone(pin, 500);
delay(500);
noTone(pin);
delay(500);
tone(pin, 500);
delay(500);
noTone(pin);
delay(500);
tone(pin, 500);
delay(500);
noTone(pin);
delay(500);
}
void Buzzer::toHigh() {
tone(pin, 600);
delay(200);
noTone(pin);
delay(200);
tone(pin, 600);
delay(200);
noTone(pin);
delay(400);
tone(pin, 600);
delay(200);
noTone(pin);
delay(200);
tone(pin, 600);
delay(200);
noTone(pin);
delay(400);
tone(pin, 600);
delay(200);
noTone(pin);
delay(200);
tone(pin, 600);
delay(200);
noTone(pin);
delay(400);
}
void Buzzer::init() {
pinMode(pin, OUTPUT);
}
void Buzzer::on(Status status) {
if (prev_status == Low && status == Mid) {
toMid();
prev_status = Mid;
}
else if (prev_status == Mid && status == High) {
toHigh();
prev_status = High;
}
else if (status == Low)
prev_status = Low;
}