Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Reciever Code (Teensy 2)
- #include <VirtualWire.h>
- int red, green, blue;
- int RedPin = 4;
- int GreenPin = 9;
- int BluePin = 10;
- char cRGB[8];
- char Cred[2],Cgreen[2],Cblue[2];
- void setup()
- {
- Serial.begin(9600);
- pinMode(RedPin, OUTPUT);
- pinMode(GreenPin, OUTPUT);
- pinMode(BluePin, OUTPUT);
- vw_setup(4000);
- vw_set_rx_pin(7);
- vw_rx_start();
- }
- void loop(){
- uint8_t buf[VW_MAX_MESSAGE_LEN];
- uint8_t buflen = VW_MAX_MESSAGE_LEN;
- // Non-blocking
- if (vw_get_message(buf, &buflen))
- {
- int i;
- for (i = 0; i < buflen; i++)
- {
- cRGB[i] = char(buf[i]); //fill cRGB with msg that was received
- }
- cRGB[buflen] = '\0'; //something for safety
- // Convert cRGB Char array to smaller char arrays to eventually turn into numbers. (its awful, i know)
- Cred[0] = cRGB[1];
- Cred[1] = cRGB[2];
- red = int(strtol(Cred, NULL, 16));
- analogWrite (RedPin, red);
- Cgreen[0] = cRGB[3];
- Cgreen[1] = cRGB[4];
- green = int(strtol(Cgreen, NULL, 16));
- analogWrite (GreenPin, green);
- Cblue[0] = cRGB[5];
- Cblue[1] = cRGB[6];
- blue = int(strtol(Cblue, NULL, 16));
- analogWrite (BluePin, blue);
- Serial.println(red); //for monitoring
- Serial.println(green);
- Serial.println(blue);
- Serial.println("------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement