Sunday, March 07, 2010

March Madness Challenge - Day 7

Thumb joystick controlled RGB LED!!!

Yesterdays entry was way unsatisfying. I wanted to enumerate all the possible RGB combinations, but was impatient, and made errors. Today's project took on the issue of determining what exact PWM values were set on this RGB led, and getting a starting point to calibrate the brightness between leds so get a decent color mix. Well, I didn't get to the issue of calibration, but I did get connect 2 thumb joysticks to the led and adjust the brightness values by reading the joystick data. Hook up 3 potentiometers and you can dial the exact combination RGB values you want.




/*
* 3 Potentiometers or Joystick controled rgb led
*/


int redPin = 9; // LED connected to digital pin 9
int greenPin = 10;
int bluePin = 11;
int potR = 0;
int potG = 1;
int potB = 2;
int r,g,b = 0;

void rgb (int r, int g, int b)
{
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);

}

void setup() {
Serial.begin(9600);
Serial.println("Setup done");
}


void loop() {

r = analogRead(potR);
g = analogRead(potG);
b = analogRead(potB);

r = map(r, 0, 1023, 0, 255);
g = map(g, 0, 1023, 0, 255);
b = map(b, 0, 1023, 0, 255);

rgb(r, g, b);
Serial.print(r);
Serial.print(", ");
Serial.print(g);
Serial.print(", ");
Serial.println(b);


}




No comments: