-
Notifications
You must be signed in to change notification settings - Fork 2
/
BEEP.ino
57 lines (52 loc) · 1.24 KB
/
BEEP.ino
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
//byte bpMemory[16] = {0,0,0,0, 0,0,0,0 ,0,0,0,0, 0,0,0,0};
byte bpMemory[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
byte bpStep = 0;
long lastbp = 0;
void Beep(){
if(bpMemory[bpStep] > 0){
if(bpMemory[bpStep] < 10
&& (millis() - lastbp) > bp_span){
if(!silent) tone(bp_pin, bp_freq);
bpMemory[bpStep] += 10;
lastbp = millis();
}else if(bpMemory[bpStep] <20
&& (millis() - lastbp)
> bpMemory[bpStep] %10 *bp_span){
noTone(bp_pin);
bpMemory[bpStep] = 0;
lastbp = millis();
bpStep++; if(bpStep > 15) bpStep = 0;
}
}
}
void insMem(byte ls){ //writing on bpMemory
//dispMem();
byte v = vacantM(bpStep);
bpMemory [v] = ls;
dispMem();
}
byte vacantM(byte x){
if(bpMemory[x] == 0){
return x;
}else{
if(x < 15){
vacantM(x + 1);
}else{
vacantM(0);
}
}
}
void dispMem(){
for( int i = 0; i < 4; i++){
for(int c = 0; c < 4; c++){
Serial.print(bpMemory[i*4 + c]);
}
Serial.print(' ');
}
Serial.println();
}
void switchon (){
tone(bp_pin, bp_freq, bp_span -10);
delay(bp_span );
tone(bp_pin, bp_freq *1.5, bp_span -10);
}