Im Trying to help a friend of mine with a RGB LED Control system for giant kaleidoscopes hes building, he is looking for a specific effect and Im having trouble finding anything similar on the web:
He wants a "Breathing" "Pulsating" or "Throbbing" effect that dims right down to near or complete darkness before building up again in next colour in sequence.
Ive found some code for a nice breathing effect on a single colour LED :
int ledPin = 13;
int x = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int outVal = yforx(x);
analogWrite(ledPin, outVal);
delay(18);
x++;
}
int yforx(int x) {
return (-240*abs(sin(x*0.01)))+255; //sine wave
}
And Ive also found code for changing between 7 colours:
/***************************
Author: Seth Leeper
Version: 1
Purpose: To cycle the tri-color LED
contained within the Sparkfun starter kit
through every available color combination with
a fade in/fade out effect.
************************************/
int RED = 5; // RED pin of the LED to PWM pin 9
int GREEN = 6; // GREEN pin of the LED to PWM pin 10
int BLUE = 7; // BLUE pin of the LED to PWM pin 11
int DELAY_TIME = 15; //changes speed of fading
int MAX_BRIGHT = 255; //sets maximum brightness, 255 max brightness
int COLOR_MIX = 0; //variable to change the colors that are mixed in switch statement
void fade_in(int x) //loop that gradually turns the LED on using PWM
{
int counter;
for(counter = 0; counter < x; counter++)
{
led_mixer(COLOR_MIX, counter);
delay(DELAY_TIME);
}
}
void fade_out(int x) //loop that gradually turns the LED off using PWM
{
int counter;
for(counter = x; counter > 0; counter--)
{
led_mixer(COLOR_MIX, counter);
delay(DELAY_TIME);
}
}
void led_mixer(int color, int x) //uses switch statement to mix color combinations
{
switch(color)
{
case 0:
analogWrite(RED, x);
break;
case 1:
analogWrite(GREEN, x);
break;
case 2:
analogWrite(BLUE, x);
break;
case 3:
analogWrite(BLUE, x);
analogWrite(GREEN, x);
break;
case 4:
analogWrite(RED, x);
analogWrite(BLUE, x);
break;
case 5:
analogWrite(RED, x);
analogWrite(GREEN, x);
break;
default:
analogWrite(GREEN, x);
analogWrite(BLUE, x);
analogWrite(RED, x);
break;
}
}
void setup()
{
// nothing for setup
}
void loop() //loop forever
{
fade_in(MAX_BRIGHT); //gradually turn the LED on to max brightness
fade_out(MAX_BRIGHT); //gradually turn off the LED
COLOR_MIX++; //increment to the next color combination
if(COLOR_MIX == 7) //if all color combinations have been displayed, reset the cycle
{
COLOR_MIX = 0;
}
}
Im just having problems combining the two programs, im not looking for a smooth fade, If I was I would have plenty of code to pick from, Problem is that I need the brightness to die right down before next colour comes in,
Can anyone offer any assistance or point me in the direction of something similar thats already out there?
Thanks.
P.S. Im new to arduino and havnt time to learn it all from scratch as ive other projects to work on so im trying to use code I can find on net and modify it to save some time but Im starting to realise this is harder than I thought!