-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBuzzer.h
60 lines (47 loc) · 971 Bytes
/
MyBuzzer.h
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
/** External Code Import(s) **/
// NoOp
/** Local Code Import(s) **/
// NoOp
/** Local Macro Import(s) **/
#include "hardware_config.h"
/** Local Macro(s) **/
// NoOp
/** Local Global Variable(s) **/
// NoOp
class MyBuzzer {
private:
unsigned char pin_;
unsigned char tone_;
bool state_;
public:
MyBuzzer (unsigned char pin = BUZZER_PIN, unsigned char buzTone = DEFAULT_BUZZER_TONE, bool state = false) {
pin_ = pin;
tone_ = buzTone;
state_ = state;
if (state_) {
tone(pin_, tone_);
} else {
noTone(pin_);
}
}
void on() {
state_ = true;
tone(pin_, tone_);
}
void off() {
state_ = false;
noTone(pin_);
}
void setTone(unsigned char buzTone) {
tone_ = buzTone;
}
unsigned char getTone() {
return tone_;
}
void setState(bool state) {
state_ = state;
}
bool getState() {
return state_;
}
};