This is my heart mood light, i have two LED lights a blue and red one. They fad from on and off at different times to switch up the colors and make purple at once. I used the Arduino to create this and just a simple plastic heart.
Video of the heart in action - heart mood light - YouTube
code:
int rPin = 5;
int bPin = 3;
int rVal = 0;
void setup(){
pinMode(rPin, OUTPUT);
pinMode(bPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
// Fade on
for(int i=0; i<255; i++){
analogWrite(rPin, i);
analogWrite(bPin, abs(255-i));
delay(10);
Serial.println(i);
}
//Fade off
for(int i=0; i<255; i++){
analogWrite(rPin,abs(255-i) );
analogWrite(bPin,i);
delay(10);
Serial.println(i);
}
/*
if(cnt < 255){
analogWrite(rPin, cnt);
analogWrite(bPin, abs(255-cnt));
cnt = cnt+1;
delay(10);
Serial.println(cnt);
} else if (cnt > 0){
analogWrite(rPin, abs(255-cnt));
analogWrite(bPin, cnt);
cnt = cnt-1;
delay(10);
}
*/
}