dougp:
Code in setup() functions like any other but once you hit the closing brace control passes to loop() thereafter.
To be clear, it won't stagger the timers once timer.run is being called from the loop ?
dougp:
What's the purpose of 'staggering'?
I have two functions in the code, it has been suggested that they could be taking too long to process when called at the same time. I can post the full code but wanted to clarify this single point.
@blh64 I will try that code now and see what happens. I am using the Blynk timer. The library is <BlynkSimpleEsp8266.h>.
@gfvalvo I will post the code next, I understand what you mean. I didn’t want to confuse the situation as the problem I am having is unusual (using Blynk terminal widget, I am getting duplicate code in the terminal window).
I have of course posted on Blynk forums, but I wondered about this specific thing (staggering timers).
#define BLYNK_PRINT Serial // Defines the object that is used for printing Blynk stuff
#include <BlynkSimpleEsp8266.h>
//Blynk credentials
char auth[] = ""; // v009 TEST Breadboard auth token
//Wifi credentials
char ssid[] = ""; //Enter your WIFI Name
char pass[] = ""; //Enter your WIFI Password
//Server credentials
char server[] = "";
int port = xxxx;
//SimpleTimer timer; //setup simple timer to call functions on a timed basis from void loop
BlynkTimer timer; // v009 improvement http://docs.blynk.cc/#blynk-firmware-blynktimer
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, server, port); //connects to Wifi and LOCAL Blynk server (running on raspberry pi)
//Setup Blynktimers
timer.setInterval(1000L, function_1);
delay(500);
timer.setInterval(1000L, function_2);
void loop()
{
Blynk.run(); //This function should be called frequently to process incoming commands and perform housekeeping of Blynk connection.
timer.run(); //Initiates SimpleTimer to runs timed functions
}
void function_1()
{
Serial.print("function1: ");
Serial.println( millis() );
}
void function_2()
{
Serial.print("function2: ");
Serial.println( millis() );
}
877:
I'm assuming when the timers are first inititated in void setup() the millis is recorded then?
Basically. Take a look at the source code in 'BlynkTimer.cpp'. You'll see that the 'setInterval()' method calls 'setupTimer()' which records the current value of millis() in the 'prev_millis' member of its internal timer structure. All timing going forward is based on that initial reading.
IMO, you should always try to dig into the source code of libraries you're using when you really want to know the guts of how they work. I've learned a great deal that way.
gfvalvo:
Basically. Take a look at the source code in 'BlynkTimer.cpp'. You'll see that the 'setInterval()' method calls 'setupTimer()' which records the current value of millis() in the 'prev_millis' member of its internal timer structure. All timing going forward is based on that initial reading.
IMO, you should always try to dig into the source code of libraries you're using when you really want to know the guts of how they work. I've learned a great deal that way.
Thanks, I understand now.
It never occurred to look in the library files, thanks for the advice!!