Go Down

Topic: RGB LED controlled with RC (Read 982 times) previous topic - next topic

jackal858

Hey everyone,

It has been a while since I posted on these forums, or did anything with my Arduino for that matter. Was busy finishing up grad school, but I suddenly find myself with a lot more free time now, which allows me to get back to some backlogged project ideas like this one. This one is fairly basic, but thought someone might be able to use it or learn from it like I did.

The concept was to be able to control the color of an RGB LED through a RC transmitter and receiver which I pulled out of a $8 RC car from RadioShack. The video I linked below goes through the three main iterations of the process I went through until getting to the final result which I wanted from the beginning (so skip to about half way through if you're just interested in the final result). The code could probably be cleaned up, but it works. I want to retrofit this into a lamp in order to have a remote control mood light of sorts.  ;)

Hope someone gets something out of it! I can answer any questions if you have them. Thanks!

Video: http://www.youtube.com/watch?v=GnVPBQuU-us

Code: [Select]
/*Code created by Robert Spann for the control of the R, G, and B values
for an RGB LED via remote control from RC Car*/

long value_RED;
long value_GREEN;
long value_BLUE;
int ledRed = 9;                           // red LED connected to pwm pin 9
int ledBlue = 10;                          // blue LED connected to pwm pin 10
int ledGreen = 11;                         // green LED connected to pwm pin 11
const int Up = 2;
const int Down = 3;
const int Left = 4;
const int Right = 5;
const int Mod = 6;
int Up1 = 0;
int Down1 = 0;
int Left1 = 0;
int Right1 = 0;
int Mod1 = 0;

void setup() {
 Serial.begin(9600);
 pinMode(Up, INPUT);
 pinMode(Down, INPUT);
 pinMode(Left, INPUT);
 pinMode(Right, INPUT);
 pinMode(Mod, INPUT);
 pinMode(ledRed, OUTPUT);
 pinMode(ledGreen, OUTPUT);
 pinMode(ledBlue, OUTPUT);
 
}

void loop() {
 Up1 = digitalRead(Up);
 Down1 = digitalRead(Down);
 Left1 = digitalRead(Left);
 Right1 = digitalRead(Right);
 Mod1 = digitalRead(Mod);
 
 //RED CONTROL*************************************
 
 if (Up1 == HIGH && Mod1 == LOW) {
     redUP();
 }
 
 if (Up1 == HIGH && Mod1 == HIGH) {
     redDOWN();
 }
    Serial.print(value_RED);
    Serial.print(" ");
   
  //***********************************************
     
  //GREEN CONTROL**********************************  
 
   if (Down1 == HIGH && Mod1 == LOW) {
     greenUP();
 }
 
   if (Down1 == HIGH && Mod1 == HIGH) {
     greenDOWN();
 }
    Serial.print(value_GREEN);
    Serial.print(" ");
     
   
 //BLUE CONTROL**********************************  
 
 if (Right1 == LOW && Mod1 == LOW) {
     blueUP();
 }
 
 if (Right1 == LOW && Mod1 == HIGH) {
     blueDOWN();
 }
    Serial.print(value_BLUE);
    Serial.print(" ");
 
   
   //***********************************************
   Serial.print(" ");
   
   if (Mod1 == HIGH) {
     Serial.print("DOWN");
   }
     else {
       Serial.print("UP");
     }
     
  Serial.println("");
   
   // LIMITS VALUES TO 2 AND 253
   
   if (value_RED >= 253) {
     value_RED = 253;
   }
   
   if (value_GREEN >= 253) {
     value_GREEN = 253;
   }
   
   if (value_BLUE >= 253) {
     value_BLUE = 253;
   }
   
   if (value_RED <= 2) {
     value_RED = 2;
   }
   
    if (value_GREEN <= 2) {
     value_GREEN = 2;
   }
   
    if (value_BLUE <= 2) {
     value_BLUE = 2;
   }
}

void redUP () {
   value_RED = (value_RED + 2);
   analogWrite(ledRed, value_RED);
 }
 
void greenUP () {
   value_GREEN = (value_GREEN + 2);
   analogWrite(ledGreen, value_GREEN);
}

void blueUP () {
   value_BLUE = (value_BLUE + 2);
   analogWrite(ledBlue, value_BLUE);
}

void redDOWN() {
   value_RED = (value_RED - 2);
   analogWrite(ledRed, value_RED);
}

void greenDOWN() {
   value_GREEN = (value_GREEN - 2);
   analogWrite(ledGreen, value_GREEN);
}

void blueDOWN() {
   value_BLUE = (value_BLUE - 2);
   analogWrite(ledBlue, value_BLUE);
}



Go Up