Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- rf_receiver
- This sketch will receive a rf signal, and decode it. If it conforms,
- it will proceed to toggle the state of a relay. Receiver on pin 3 (5)
- */
- #include <VirtualWire.h>
- byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
- byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
- int led = 1;
- int lstate = 0;
- void setup()
- {
- //Serial.begin(9600);
- //Serial.println("Device is ready");
- // Initialize the IO and ISR
- vw_setup(2000); // Bits per sec
- vw_set_rx_pin(0);
- vw_rx_start(); // Start the receiver
- pinMode(led, OUTPUT);
- digitalWrite(led, HIGH);
- }
- void loop()
- {
- char currState;
- if (vw_get_message(message, &messageLength)) // Non-blocking
- {
- //Serial.print("Received: ");
- for (int i = 0; i < messageLength; i++)
- {
- if (message[0] == 'L' && message[1] == '0' && message[2] == '1'){
- if (lstate == 0) {
- digitalWrite(led, HIGH);
- lstate = 1;
- } else {
- digitalWrite(led, LOW);
- lstate = 0;
- }
- }
- else if (message[0] == 'M' && message[1] == '0' && message[2] == '1' ){
- digitalWrite(led, LOW);
- }
- else {
- //Serial.write(message[2]);
- }
- }
- //Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement