I recently bought a 5050 RGB 12V 3A LED strip and I set it all up with my Arduino and run this code (from adafruit website), everything is good: Example Code Once you have the strip wired up, it is easy to control the color of the strip by using PWM output, for Arduino you can use
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
#define FADESPEED 5 // make this higher to slow down
void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}
void loop() {
int r, g, b;
// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
}
I tried to find a way to achieve the same effect but only with two colors...red to yellow..red fade to yellow and fade to red and so on..
EDIT: Thanks to @majenko I achieved this...Fade from Red to Yellow and back on:
for (int r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
analogWrite(GREENPINPIN, 255 - r);
analogWrite(BLUEPIN, 0);
delay(FADESPEED);
}
// Fade red down and blue up
for (g = 0; g < 256; g++) {
analogWrite(REDPIN, 255);
analogWrite(BLUEPIN, 0);
analogWrite(GREENPINPIN, G);
delay(FADESPEED);
}