Project 9 RGB LED

1. Introduction: Tricolor principle to display various colors;PWM controlling ports to display full color;Can be driven directly by Arduino PWM interfaces.

2. Hardware Required:
Arduino controller × 1
USB cable × 1
Full-color LED module × 1
3. Connection for REV4

4. Connection for 2560 R3

5. Sample Code
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(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
for(val=0; val<255; val++)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
Serial.println(val, DEC);
}
Result:
Directly copy the above code into arduino IDE, and click upload
,wait for a few seconds, you can see a full-color LED.
