A LED-module which provides a red, blue and green LED. These are connected with a common cathode. A resistor is necessary for different voltages.
Vf [Red]= 1,8V
Vf [Green,Blue]= 2,8V
If= 20mA
Pre-resistor:
Rf (3,3V) [Green]= 100Ω
Rf (3,3V) [Red]= 180Ω
Rf (3,3V) [Blue]= 100Ω
Example:
The following Arduino sketch will cycle through various colors by changing the PWM value on each of the three primary colors.
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin = 9;// select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
for(val = 255; val > 0; val--)
{
analogWrite(redpin, val); //set PWM value for red
analogWrite(bluepin, 255 - val); //set PWM value for blue
analogWrite(greenpin, 128 - val); //set PWM value for green
Serial.println(val); //print current value
delay(1);
}
for(val = 0; val < 255; val++)
{
analogWrite(redpin, val);
analogWrite(bluepin, 255 - val);
analogWrite(greenpin, 128 - val);
Serial.println(val);
delay(1);
}
}