I want to control the order of fading in and out of 4 led strips. Everything is related to connecting it is done, the only issue I'm facing now is in the code.
I want to start by initially increasing the brightness of led3 and with a litte delay start increasing the brightness of led2 and after that led1. And until the led1 s at full brightnes the led2 and led1 stay at full brightnes. Then after that all the three led1, led2, led3 decrease in brightness and at the same time led4 increases in brightness. Then when led4 reaches full brightnes it's brightness starts to decrease and again the process starts.
Code:
int led1 = 3;
int led2 = 5;
int led3 = 6;
int led4 = 9;
float brightness1 = 0;
float brightness2 = 0;
float brightness3 = 0;
float brightness4 = 0;
int fadeAmount = 1;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
if(brightness3 < 255 )
brightness3 = brightness3 + 2.5;
analogWrite(led3, brightness3);
delay(1);
brightness2 = brightness2 + 0.5;
analogWrite(led2, brightness2);
delay(1);
brightness1 = brightness1 + 0.25;
analogWrite(led1, brightness1);
delay(1);
if (brightness1 == 255)
{ do
{
brightness4 = brightness4 + 5;
analogWrite(led4, brightness4);
if(brightness2 > 0 )
{analogWrite(led2, brightness2 = brightness2 - 0.5);
}
if(brightness3 > 0)
{analogWrite(led3, brightness3 = brightness3 - 2.5);
}
if(brightness1 > 0)
{analogWrite(led1, brightness1 = brightness1 - 0.25);
}
delay(10);
}while(brightness4 <254 );
delay(10);
do
{ analogWrite(led4, brightness4 = brightness4 -1);
delay(10);
}while(brightness4 > 0);
}
}