-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBeepController.h
59 lines (43 loc) · 1011 Bytes
/
BeepController.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
////////////////////////////////////////////////////
// State machine to control the beeping
////////////////////////////////////////////////////
#ifndef BeepController_h
#define BeepController_h
////////////////////////////////////
// State enums
class CBeepController
{
public:
typedef enum
{
beepIdle = 0,
beepStart,
beepOn,
beepOff,
} beepStateE;
private:
beepStateE m_state;
unsigned long m_beginningTime; // Unit is 1 millisecond. (millis())
void setState(beepStateE _state);
int m_freq;
unsigned long m_onTime;
unsigned long m_offTime;
int m_repeats;
bool m_alarm;
int m_beepOutPin;
int m_beepGndPin;
public:
CBeepController(int _pinOut, int _pinGnd = -1);
beepStateE state()
{
return m_state;
}
void setup();
void tick();
void beep(int _freq, unsigned long _onTime, unsigned long _offTime, int _repeats);
};
#define BEEP_FREQ_BEST (4000) // Hz
#define BEEP_FREQ_ERROR (4000)
#define BEEP_FREQ_INFO (2000)
extern CBeepController g_beepController;
#endif