If you use Blynk, you are restricted to 16 timers, along with 10 RTOS timers in Particle enviroment. In a complex project, these timers may be exhausted quickly. One solution is to implement timers within the loop; an example follows.
void loop()
{
Blynk.run();
timer.run();
const uint64_t now = System.millis();
// Timer 1
static uint64_t lastTimeUpdate = 0;
if (now - lastTimeUpdate >= 1000ULL)
{
lastTimeUpdate = now;
if (Blynk.connected())
{
displayTimeOnV10();
}
}
// Timer 2
static uint64_t lastBatteryUpdate = 0;
if (now - lastBatteryUpdate >= 5000ULL)
{
lastBatteryUpdate = now;
updateBatterySystem();
}
// Timer 3
static uint64_t lastTFTUpdate = 0;
if (now - lastTFTUpdate >= 250ULL)
{
lastTFTUpdate = now;
updateTFTBrightness();
}
}
Because you're using uint64_t with System.millis(), you've also got an absurdly long rollover horizon( compared with ordinary 32-bit millis() A one MS timer will take 584.5 million years to roll over compare to 49.7 days on a 32 bits timer. This is clean, non-blocking, and scalable approach. I am using the Photon2.