-
Notifications
You must be signed in to change notification settings - Fork 0
/
buzzer.hpp
75 lines (56 loc) · 1.64 KB
/
buzzer.hpp
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
#ifndef BUZZER_HPP
#define BUZZER_HPP
class buzzer_control
{
public:
buzzer_control( byte pin );
void init();
void buttons( const byte &event_button_plus, const byte &event_button_minus, const byte &event_button_select, const byte &event_button_start );
void finish();
protected:
const byte pin;
};
buzzer_control::buzzer_control( byte p )
: pin(p)
{
}
void buzzer_control::init()
{
// initialize buzzer pin
pinMode(pin, OUTPUT);
}
inline void buzzer_control::buttons( const byte &event_button_plus, const byte &event_button_minus, const byte &event_button_select, const byte &event_button_start )
{
byte button_short_pressed = 0;
button_short_pressed |= event_button_plus;
button_short_pressed |= event_button_minus;
button_short_pressed |= event_button_select;
button_short_pressed |= event_button_start;
button_short_pressed &= 1;
byte button_long_pressed = 0;
button_long_pressed |= event_button_plus;
button_long_pressed |= event_button_minus;
button_long_pressed |= event_button_select;
button_long_pressed |= event_button_start;
button_long_pressed &= 2;
byte button_secret_pressed = 0;
//button_secret_pressed |= event_button_plus;
//button_secret_pressed |= event_button_minus;
//button_secret_pressed |= event_button_select;
button_secret_pressed |= event_button_start;
button_secret_pressed &= 4;
if ( button_short_pressed == 1 ) {
tone(pin, 500, 200);
} else if ( button_long_pressed == 2 ) {
tone(pin, 700, 400);
} else if ( button_secret_pressed == 4 ) {
tone(pin, 800, 500);
} else {
//noTone(8);
}
}
void buzzer_control::finish()
{
tone(pin, 700, 5000);
}
#endif // BUZZER_HPP