Want more features on Pastebin? Sign Up, it's FREE!
Guest

rxfixed

By: a guest on Jun 4th, 2013  |  syntax: C  |  size: 1.28 KB  |  views: 3  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Reciever Code (Leonardo)
  2. #include <VirtualWire.h>
  3. int red, green, blue, oldred,oldblue,oldgreen=12; //red, green and blue values
  4.  
  5. int RedPin = 12;
  6. int GreenPin = 9;
  7. int BluePin = 10;
  8. char cRGB[8], Cred[3], Cgreen[3], Cblue[3];
  9. String hRGB, Sred, Sgreen, Sblue;
  10. void setup()
  11. {
  12.   Serial.begin(9600);
  13.   pinMode(RedPin, OUTPUT);
  14.   pinMode(GreenPin, OUTPUT);
  15.   pinMode(BluePin, OUTPUT);
  16.  
  17.   vw_setup(5000);
  18.   vw_set_rx_pin(7);
  19.   vw_rx_start();
  20. }
  21.  
  22. void loop(){
  23.     uint8_t buf[VW_MAX_MESSAGE_LEN];
  24.     uint8_t buflen = VW_MAX_MESSAGE_LEN;
  25.    
  26.     // Non-blocking
  27.     if (vw_get_message(buf, &buflen))
  28.     {
  29.     int i;
  30.         for (i = 0; i < buflen; i++)
  31.     {            
  32.           cRGB[i] = char(buf[i]);
  33.     }
  34.         cRGB[buflen] = '\0';
  35.         // Convert cRGB Char array to string hRGB
  36.     hRGB = cRGB;
  37.     Sred = hRGB.substring(1,3);
  38.     Sred.toCharArray(Cred,3);
  39.     red = (int)strtol(Cred, NULL, 16);
  40.    
  41.     Sgreen = hRGB.substring(3,5);
  42.     Sgreen.toCharArray(Cgreen,3);
  43.     green = (int)strtol(Cgreen, NULL, 16);
  44.  
  45.     Sblue = hRGB.substring(5,7);
  46.     Sblue.toCharArray(Cblue,3);
  47.     blue = (int)strtol(Cblue, NULL, 16);
  48.    
  49.         analogWrite (RedPin, red);
  50.         analogWrite (GreenPin, green);
  51.         analogWrite (BluePin, blue);
  52.     }
  53. }
clone this paste RAW Paste Data