Third parameter controls speed of effect, so you’re going to have to time it and mess around.
Delay() stops code executing...so does it interrupt the breathing pattern too? If you set a long delay does the led “hold its breath”? If so use millis()...set a “start” variable when you trigger the first, then put in an if statement to check for;
millis()-start >= (value you need here)
And start the second one...you could even use a random value up between (for example) a quarter and three quarters of the “breath” length.
This offcourse do not work as the millis(); just climbs as I belive it's the time the arduino has been on. So what happens here is that the led connected to 1 works fine after 3sec, but the first just stays lit.
Is there an way to restart the timer back to zero?
Yes, as I said, you need to assign millis to a variable when you trigger the breathe routine...
But you have BOTH LEDS dependant on an “if” statement...do you need that? I thought you were just starting one and offsetting the second;
#include <Breathe.h>
Breathe Breathe;
void setup(){
}
void loop(){
long currentMillis = millis();
Breathe.set(0, HIGH, 1, 20);
currentMillis = millis(); // start the timer when you start the breathe, not when you start the sketch!
if (currentMillis > 3000){ // then this time is “since led 0 started breathing”
Breathe.set(1, HIGH, 1, 20);
// currentMillis=millis(); if necessary, set again here then It’s “since led 1 started breathing”
}
}
What do you mean by that? The code works great with what you wrote.. Do you have an example so I can learn for future projects on why a second variable will be a good idea?
Well, if you have two timers, you need to delay one relevant to the other. I guess with just two LEDs you could reset the same variable each time a timer starts...but what if you build to three,or four...or ten...and you still want it that none of the breathing LEDs are synchronised?
You’re going to need a start time for each one...so probably easier to start using the same concept now, rather than reprogram later...