Improve loop counter

This commit is contained in:
fvanroie 2020-04-03 18:37:35 +02:00
parent ebc12fc14a
commit 8cfcfd750a

View File

@ -125,6 +125,8 @@ void setup()
#if HASP_USE_BUTTON #if HASP_USE_BUTTON
buttonSetup(); buttonSetup();
#endif #endif
mainLastLoopTime = millis() - 1000;
} }
void loop() void loop()
@ -178,13 +180,6 @@ void loop()
// Every Second Loop // Every Second Loop
if(millis() - mainLastLoopTime >= 1000) { if(millis() - mainLastLoopTime >= 1000) {
/* Update counters */
mainLastLoopTime += 1000;
mainLoopCounter++;
if(mainLoopCounter >= 10) {
mainLoopCounter = 0;
}
/* Run Every Second */ /* Run Every Second */
#if HASP_USE_OTA #if HASP_USE_OTA
otaEverySecond(); otaEverySecond();
@ -192,11 +187,18 @@ void loop()
debugEverySecond(); debugEverySecond();
/* Run Every 5 Seconds */ /* Run Every 5 Seconds */
if(mainLoopCounter == 0 || mainLoopCounter == 5) { if(mainLoopCounter == 0 || mainLoopCounter == 4) {
httpEvery5Seconds(); httpEvery5Seconds();
isConnected = wifiEvery5Seconds(); isConnected = wifiEvery5Seconds();
mqttEvery5Seconds(isConnected); mqttEvery5Seconds(isConnected);
} }
/* Update counters */
mainLastLoopTime += 1000;
mainLoopCounter++;
if(mainLoopCounter >= 10) {
mainLoopCounter = 0;
}
} }
delay(3); delay(3);