//Transmitter Code (Uno)
#include <VirtualWire.h>
int red, green, blue;
String RGB;
char cRGB[8];
void setup()
{
Serial.begin(9600);
int red = 255;
int blue = 255;
int green = 255;
vw_setup(4000);
vw_set_tx_pin(7);
}
void loop()
{
//protocol expects data in format of 4 bytes
//(xff) as a marker to ensure proper synchronization always
//followed by red, green, blue bytes
if (Serial.available()>=4)
{
if(Serial.read() == 0xff)
{
red = Serial.read();
green= Serial.read();
blue = Serial.read();
}
}
//here is my shitty way to convert the rgb into a hex color
RGB = "F"; //starting with "F" (easier to un-hex for the receiver)
if (red<=16){
RGB += "0"+String(red,HEX);}
else if (red>16){RGB+=String(red,HEX);}
if (green<=16){
RGB += "0"+String(green,HEX);}
else if (green>16){RGB+=String(green,HEX);}
if (blue<=16){
RGB += "0"+String(blue,HEX);}
else if (blue>16){RGB+=String(blue,HEX);}
// example of end result from the rgb color (10,10,10) = F0A0A0A
RGB.toCharArray(cRGB,8);
vw_send((uint8_t *)cRGB, 8);
}