September 23, 2008

Triple Potentiometer with RGB LED

I wanted to perfect this particular configuration so I went ahead and did a little more research to make sure it worked.  Once I got the right spec setup for the RGB LED (I assumed it’s setup was a logical interpretation but once I got my eyes on the right setup I realized I was wrong).  I also had to reinstall the whole setup on the Arduino board for the PWM inputs and then everything was perfect.  Check it out.

PhyComp Week 2 extra Lab, Triple Potentiometer RGB LED

Code:

int potPin0 = 0;    // Analog input pin that the potentiometer is attached to
int potPin1 = 1;
int potPin2 = 2;

int potValue0 = 0;   // value read from the pot
int potValue1 = 0;
int potValue2 = 0;

int led9 = 9;    // PWM pin that the LED is on.  n.b. PWM 0 is on digital pin 9
int led10 = 10;
int led11 = 11;

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
potValue0 = analogRead(potPin0); // read the pot value
potValue1 = analogRead(potPin1);
potValue2 = analogRead(potPin2);

analogWrite(led9, potValue0/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
analogWrite(led10, potValue1/4);
analogWrite(led11, potValue2/4);

Serial.println(potValue2);      // print the pot value back to the debugger pane
delay(10);                     // wait 10 milliseconds before the next loop
}