-
Notifications
You must be signed in to change notification settings - Fork 0
/
rf_led_transmit.ino
107 lines (79 loc) · 2.14 KB
/
rf_led_transmit.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
#include <VirtualWire.h>
const int RF_TX_PIN = 8;
const int pinLamp_ON_OFF = 2;
const int pinLock_ON_OFF = 3;
const int pinFan_ON_OFF = 5;
const int pinLED_ON_OFF = 6;
int pinLed = 4;
char payload[6] = "";
int relayLamp_on_off_Value = 0;
int relayFan_on_off_Value = 0;
int relayLock_on_off_Value = 0;
int relayLed_on_off_Value = 0;
void setup() {
// put your setup code here, to run once:
vw_set_ptt_inverted(true);
vw_set_tx_pin(RF_TX_PIN);
vw_setup(2000);
pinMode(pinLED_ON_OFF, INPUT_PULLUP);
pinMode(pinLamp_ON_OFF, INPUT_PULLUP);
pinMode(pinLock_ON_OFF, INPUT_PULLUP);
pinMode(pinFan_ON_OFF, INPUT_PULLUP);
pinMode(pinLed, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
relayLamp_on_off_Value = digitalRead(pinLamp_ON_OFF);
relayLock_on_off_Value = digitalRead(pinLock_ON_OFF);
relayFan_on_off_Value = digitalRead(pinFan_ON_OFF);
relayLed_on_off_Value = digitalRead(pinLED_ON_OFF);
//using pullup, the values are inverted
if(relayLed_on_off_Value == LOW){
digitalWrite(pinLed, HIGH);
strcpy(payload, "@ABC$");
if(strlen(payload) > 0){
sendPayload(payload);
}
delay(500);
digitalWrite(pinLed, LOW);
}
if(relayFan_on_off_Value == LOW ){
digitalWrite(pinLed, HIGH);
strcpy(payload, "@FON$");
if(strlen(payload) > 0){
sendPayload(payload);
}
digitalWrite(pinLed, LOW);
}
if(relayLamp_on_off_Value == LOW ){
digitalWrite(pinLed, HIGH);
strcpy(payload, "@LON$");
if(strlen(payload) > 0){
sendPayload(payload);
}
digitalWrite(pinLed, LOW);
}
if(relayLock_on_off_Value == LOW ){
digitalWrite(pinLed, HIGH);
strcpy(payload, "@LCK$");
if(strlen(payload) > 0){
sendPayload(payload);
}
digitalWrite(pinLed, LOW);
}
strcpy(payload, "");
resetLoads();
}
void sendPayload(char payload[]){
vw_send((uint8_t *)payload, strlen(payload));
Serial.println(payload);
vw_wait_tx();
delay(400);
}
void resetLoads(){
relayLamp_on_off_Value = 0;
relayFan_on_off_Value = 0;
relayLock_on_off_Value = 0;
relayLed_on_off_Value = 0;
}