-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.pde
107 lines (88 loc) · 1.8 KB
/
receiver.pde
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
#include <VirtualWire.h>
#include <ServoTimer2.h>
const int piezo_pin = 2;
const int led_pin = 12;
const int receive_pin = 11;
const int servo_pin = 9;
long lastTrigger = 0;
ServoTimer2 myservo;
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
pinMode(led_pin, OUTPUT);
pinMode(piezo_pin, OUTPUT);
myservo.attach(servo_pin);
myservo.write(0);
delay(750);
myservo.detach();
beep();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if (lastTrigger < millis())
{
int i;
byte matched = 0;
char msg[7] = {1,8,2,3,5,9,4};
digitalWrite(led_pin, HIGH);
for (i = 0; i < buflen; i++)
{
if (buf[i] == msg[i])
{
matched++;
}
Serial.print(buf[i], DEC);
}
if (matched == buflen)
{
pull();
Serial.println("Matched");
lastTrigger = millis() + 5000;
}
else
{
Serial.println("Not matched");
}
matched = 0;
digitalWrite(led_pin, LOW);
}
}
String content = "";
char character;
while(Serial.available()) {
character = Serial.read();
content.concat(character);
}
if (content == "1") {
pull();
}
}
void beep()
{
digitalWrite(piezo_pin, HIGH);
delay(50);
digitalWrite(piezo_pin, LOW);
}
void pull()
{
myservo.attach(servo_pin);
myservo.write(2000);
beep();
delay(75);
beep();
delay(75);
beep();
delay(750);
myservo.write(0);
delay(750);
myservo.detach();
}