forked from awall9999/UD-Alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver001.ino
114 lines (75 loc) · 2.58 KB
/
receiver001.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Rx Pager Mini
With Buzzer and Led
*/
#include <RCSwitch.h>
const int ButtonReset = 3;
const int LedFlashA = 12;
const int LedFlashB = 13;
const int SirenePin = 5;
const int RfModul = 0; // Receiver on interrupt 0 / Pin 2 on Arduino 328P
const int AlarmCode = 20191; // this is the transmitted code of the Belt
unsigned long TimeNow_One = 0;
boolean Alarm = false;
long int Counter=0;
RCSwitch mySwitch = RCSwitch();
void TheDelay(int Delay){
TimeNow_One = millis();
do {
if (digitalRead(ButtonReset)== 0){ResetAlarm();Delay=0;}
} while ((unsigned long)(millis() - TimeNow_One) < Delay);
}
void ResetAlarm(){
noTone(SirenePin);
Alarm = false;
digitalWrite(LedFlashA,LOW);
digitalWrite(LedFlashB,LOW);
}
void BeepBeep(int Repeat) {
for (int i = 0; i <= Repeat; i++) {
digitalWrite(LedFlashA,LOW);
digitalWrite(LedFlashB,HIGH);
tone(SirenePin,4200);
TheDelay(50);
digitalWrite(LedFlashA,HIGH);
digitalWrite(LedFlashB,LOW);
noTone(SirenePin);
TheDelay(100);
}
digitalWrite(LedFlashA,LOW);
digitalWrite(LedFlashB,LOW);
}
void LedBlink(int Repeat,int Duration) {
for (int i = 0; i <= Repeat; i++) {
digitalWrite(LedFlashA,HIGH);
digitalWrite(LedFlashB,LOW);
TheDelay(Duration);
digitalWrite(LedFlashA,LOW);
digitalWrite(LedFlashB,HIGH);
TheDelay(Duration);
}
digitalWrite(LedFlashA,LOW);
digitalWrite(LedFlashB,LOW);
}
void setup() {
analogReference(INTERNAL);
Serial.begin(9600);
mySwitch.enableReceive(RfModul); // Receiver on interrupt 0
pinMode(ButtonReset,INPUT_PULLUP);
pinMode(SirenePin,OUTPUT);
pinMode(LedFlashA,OUTPUT);
pinMode(LedFlashB,OUTPUT);
ResetAlarm();
BeepBeep(0);
}
void loop() {
if (digitalRead(ButtonReset)== 0){ResetAlarm();}
if (Alarm == true) {Counter++;if (Counter > 50000) {LedBlink(2,200);Counter=0;}}
if (mySwitch.available()) {
if (mySwitch.getReceivedValue() == AlarmCode){
BeepBeep(3);
Alarm = true;
}
mySwitch.resetAvailable();
}
}