As far as i have understood there is no limitation. But you will have to stagger the timers. There should be no delays inside the functions called by the timers.
Go through this topic. It just has all the important stuff.
this is not a smooth way how to do things using like 30 timers but I need to run multiple functions in parallel for a specific time and the usual millis() where is while is blocking everything
So the whole problem is to be able to call multiple functions, run them for a predefined time period at the same time. It is for the whole house where I have window Blinds. Sometimes I want to start rolling a window in room 1 and while it is rolling start rolling another window.
The only thing I was able to come up with which does not use blocking loops was that all these functions are being called all the time using timers and the trigger to run the code inside would be a variable state with if condition. The variable state I change with the virtual buttons in my phone.
One motor needs 2 functions, one for going up another for going down with some conditions. I have 5 motors and that is only one type of procedure like go down/up all the way. I have 4 types of these functions go half way down or open the blinds only - the angle and so on.
The whole code is done it has 2000 rows and it uses Millis functions with while which does this annoying thing once you start rolling one blind untill the loop finishes you cannot do anything else
That sounds like a situation where a timeout timer, probably as part of a lambda function, is a far better solution than having an interval timer that is running all the time.
That’s bad coding. If you did it properly then you wouldn’t need to wait. However, there is no need to use millis comparison in most situations, timeout timers are a much better option in most situations.
Pete I’m trying to use the timers but it wont work - it ignores the T1 completely - the led is not turning on, the T2 works but it never stops - what do you think is wrong here
the goal is to light the pin_led or pin_led2 for 2 seconds
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"
BlynkTimer timer;
#define pin_led 21
#define pin_led2 13
int state = 0;
int state2 = 0;
int Virtual_Button_Led1;
int Virtual_Button_Led2;
BLYNK_WRITE(V1)
{
Virtual_Button_Led1 = param.asInt();
if (Virtual_Button_Led1 == 1)
{
timer.enable(T1);
}
}
BLYNK_WRITE(V2)
{
Virtual_Button_Led2 = param.asInt();
if (Virtual_Button_Led2 == 1)
{
timer.enable(T2);
}
}
void LEDD()
{
digitalWrite(pin_led, 1);
}
void LEDD2()
{
digitalWrite(pin_led2, 1);
}
void OFF()
{
if (T1 == false)
{
digitalWrite(pin_led, 0);
}
else if (T2 == false)
{
digitalWrite(pin_led2, 0);
}
}
void setup()
{
Serial.begin(115200);
delay(100);
pinMode(pin_led, OUTPUT);
pinMode(pin_led2, OUTPUT);
int T0 = timer.setInterval(500L, OFF);
int T1 = timer.setTimer(200L, LEDD, 10);
int T2 = timer.setTimer(200L, LEDD2, 10);
timer.disable(T1); //turn the timers off when the program starts
timer.disable(T2);
BlynkEdgent.begin();
}
void loop()
{
BlynkEdgent.run();
timer.run();
}
So, I’ve suggested that you use timeout timers, preferably in a lambda function, and you’ve gone down a totally different route, then you’re telling me it doesn’t work.
You’re missing the point of timeout timers. They aren’t used to call a timer that is defined in void setup.
This example uses the BlynkTimer timer object, which needs to be defines and an object…
BlynkTimer timer;
and ‘fed’ in your void loop…
void loop()
{
timer.run(); // call the BlynkTimer object
Blynk.run(); // perform a handshake with the Blynk server
}
other than that, you simply use the timeout timer to wait x milliseconds then execute the code ‘completed’ code.
This is why you don’t need to define 30+ interval timers if you simply want to trigger an action, wait a period of time, then perform another action.