I'm having trouble figuring out how to multitask LEDs. I'm not even sure if this is possible...can I get so many smooth fades?
these are the functions i want to do...sequence3() would be pulsing constantly while the other ones are fading on, staying on, fading off:
sequence1() {
//fade to on after sequence2() fades off
//leave on, at 255 brightness for 10 seconds
//fade off
}
sequence2() {
//fade to on after sequence1() finishes
//leave on, at 255 brightness for 10 seconds
//fade off
}
sequence3() {
//fade up
//fade down
//loop this so this is happening all the time
}
void loop() {
sequence1();
sequence2();
sequence3();
}
this is what i have so far...it works starting out but then the pulsing lights stop turning on
boolean switchOn1, switchOn2;
unsigned long currentTime;
unsigned long loopTime;
unsigned long currentTime1;
unsigned long loopTime1;
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
int brightness1 = 0; // how bright the LED is
int fadeAmount1 = 2; // how many points to fade the LED by
void setup() {
switchOn1=true;
switchOn2=false;
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void sequence1() {
//fade to on after sequence2() fades off
//leave on, at 255 brightness for 10 seconds
//fade off
//if the switch is true
//fade on the led
//leave on the led for 2 seconds
//flip the switch to false
//flip on the switch that turns on the next set
//fade it out
if (switchOn1 == true){
currentTime=millis();
if(currentTime >=loopTime+20){
analogWrite(10, brightness);
brightness = brightness + fadeAmount;
loopTime = currentTime;
if (brightness >=255){
analogWrite(10, 255);
if (currentTime >=loopTime+2000){
analogWrite(10, 255);
}
else {
analogWrite(10,0);
switchOn1=false;
switchOn2=true;
}
loopTime=currentTime;
}
loopTime=currentTime;
}
}
}
void sequence2() {
//fade to on after sequence1() finishes
//leave on, at 255 brightness for 10 seconds
//fade off
if (switchOn2 == true){
currentTime=millis();
if(currentTime >=loopTime+20){
analogWrite(9, brightness);
brightness = brightness + fadeAmount;
loopTime = currentTime;
if (brightness >=255){
analogWrite(9, 255);
if (currentTime >=loopTime+2000){
analogWrite(9, 255);
}
else {
analogWrite(9,0);
switchOn1=true;
switchOn2=false;
}
loopTime=currentTime;
}
loopTime=currentTime;
}
}
}
void sequence3() {
//fade up
//fade down
//loop this so this is happening all the time
currentTime1=millis();
if(currentTime1 >=loopTime1+20){
analogWrite(11, brightness1);
brightness1 = brightness1 + fadeAmount1;
if (brightness1 ==0 || brightness1 == 255) {
fadeAmount1 = -fadeAmount1;
}
loopTime1 = currentTime1;
}
}
void loop() {
sequence1();
sequence2();
sequence3();
}