forked from nimishbongale/SmartHelmet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recieve.ino
38 lines (30 loc) · 828 Bytes
/
recieve.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
#include <VirtualWire.h>
const int receive_pin = 2;
const int relay=3;
bool relayState =false;
void setup()
{
pinMode(relay,OUTPUT);
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
(relayState==true)?(digitalWrite(13,HIGH)):(digitalWrite(13,LOW));
(relayState==true)?(digitalWrite(relay,LOW)):(digitalWrite(relay,HIGH));
if (vw_get_message(buf, &buflen)) // Non-blocking
{
Serial.println(buf[0]);
if(buf[0]==49){
relayState=false;
}
else if(buf[0]==48){
relayState=true;
}
}
}