-
Notifications
You must be signed in to change notification settings - Fork 1
/
receiver.ino
58 lines (51 loc) · 1.09 KB
/
receiver.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
#include <SoftwareSerial.h>
#include "EBYTE.h"
#define PIN_AX 2
#define PIN_TX 4
#define PIN_RX 3
#define PIN_M1 5
#define PIN_M0 6
#define SPK 7
struct DATA {
int State;
};
DATA Message;
unsigned long Last;
SoftwareSerial ESerial(PIN_RX, PIN_TX);
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);
void setup() {
ESerial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(SPK, OUTPUT);
digitalWrite(SPK, LOW);
Transceiver.init();
}
void loop() {
if (Transceiver.available()) {
Transceiver.GetStruct(&Message, sizeof(Message));
if (Message.State == 1) {
for (int i = 0; i < 3; i++) {
digitalWrite(LED_BUILTIN, HIGH);
ringTheBell();
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
} else {
digitalWrite(LED_BUILTIN, LOW);
}
Last = millis();
} else {
digitalWrite(LED_BUILTIN, LOW);
if ((millis() - Last) > 1000) {
Last = millis();
}
}
}
void ringTheBell() {
tone(SPK, 2500, 1000);
delay(1000);
tone(SPK, 1000, 2000);
delay(2000);
digitalWrite(SPK, LOW);
}