-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBeep.cpp
64 lines (60 loc) · 1.28 KB
/
Beep.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
#include "Beep.h"
Beep::Beep(int beep_pin)
{
pin = beep_pin;
}
void Beep::begin()
{
pinMode(pin, OUTPUT);
pinMode(13, OUTPUT);
}
void Beep::setBeep(int beep_type)
{
if(beep_type == PRIORITY_BEEP)
{
priority_beep = true;
priority_start = millis();
priority_end = priority_start + PRIORITY_BEEP_PERIOD;
}
else if(beep_type == NON_PRIORITY_BEEP)
{
non_priority_beep = true;
non_priority_start = millis();
non_priority_end = non_priority_start + NON_PRIORITY_BEEP_PERIOD;
}
}
void Beep::execute()
{
long time = millis();
if(priority_beep)
{
if(time > priority_start && time < priority_end)
{
digitalWrite(pin, HIGH);
digitalWrite(13, HIGH);
} else if (time > priority_end)
{
priority_beep = false;
if(!(non_priority_beep && time < non_priority_end))
{
digitalWrite(13, LOW);
digitalWrite(pin, LOW);
}
}
} else if(non_priority_beep)
{
if(time > non_priority_start && time < non_priority_end)
{
digitalWrite(pin, HIGH);
digitalWrite(13, HIGH);
} else if (time > non_priority_end)
{
non_priority_beep = false;
if(!(priority_beep && time < priority_end))
{
digitalWrite(13, LOW);
digitalWrite(pin, LOW);
}
}
}
}