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

txfixed

By: a guest on Jun 4th, 2013  |  syntax: C  |  size: 1.13 KB  |  views: 24  |  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. //Transmitter Code (Uno)
  2. #include <VirtualWire.h>
  3. int red, green, blue,oldred,oldblue,oldgreen;
  4. String RGB;
  5. char cRGB[7];
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   int red = 255;
  11.   int blue = 255;
  12.   int green = 255;
  13.   vw_setup(5000);
  14.   vw_set_tx_pin(7);
  15. }
  16.  
  17. void loop()
  18. {
  19.     if (Serial.available()>=4 && Serial.read() == 0xff)
  20.   {
  21.   red = Serial.read();
  22.   green= Serial.read();
  23.   blue = Serial.read();
  24.   }
  25.  
  26. if (oldred!=red && oldgreen!=green && oldblue!=blue){
  27. //here is my shitty way to convert the rgb into a hex color
  28.   RGB = "F"; //starting with "F" (easier to un-hex for the receiver)
  29. if (red<=16){
  30.   RGB += "0"+String(red,HEX);}
  31.   else if (red>16){RGB+=String(red,HEX);}
  32. if (green<=16){
  33.   RGB += "0"+String(green,HEX);}
  34.   else if (green>16){RGB+=String(green,HEX);}
  35. if (blue<=16){
  36.   RGB += "0"+String(blue,HEX);}
  37.   else if (blue>16){RGB+=String(blue,HEX);}  
  38. // example of end result from the rgb color (10,10,10) = F0A0A0A
  39.  
  40.  
  41.   RGB.toCharArray(cRGB,8);
  42.  
  43.       vw_send((uint8_t *)cRGB, 8);
  44.       vw_send((uint8_t *)cRGB, 8); //twice is a charm
  45.   oldblue = blue;
  46.   oldred = red;
  47.   oldgreen = green;
  48. }
  49. }
clone this paste RAW Paste Data