I've just been playing with the same type of LED. As is been said already - they are common-annode, so think in reverse. 1 pin goes to +5v the other 3 go to digital pins on the arduino. Use the example I have below to see it in action. Note the Pin assignments are to PWM pins.
- Code: Select all
// Select which PWM-capable pins are to be used.
int redPin = 9;
int greenPin = 3;
int bluePin = 10;
// Set up our outputs, and give full high values so the
// LEDs start off. Then fade in the blue LED.
//
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
// The cycle of ramps will go through all of the primary
// and secondary hues in the RGB rainbow, and repeat.
//
void loop()
{
analogWrite(redPin, 225);
//digitalWrite(redPin, LOW);
/*
//green
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
delay(2000);
//yellow
analogWrite(redPin, 0);
analogWrite(greenPin, 190);
analogWrite(bluePin, 255);
// delay(2000);
//orange
// analogWrite(redPin, 115);
// analogWrite(greenPin, 245);
// analogWrite(bluePin, 255);
delay(2000);
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
*/
delay(2000);
}