Está función se ejecuta cada segundo y cada 30 segundos respectivamente, con esto mejora el rendimiento del arduino al no ejecutar un delay
Código: Seleccionar todo
unsigned long ExTimer;
byte CountSg=0;//Cuenta los segundos de 1 - 30
byte CountMsg=0;
void setup() {
// put your setup code here, to run once:
ExTimer=millis();
}
void loop() {
unsigned long TimNow=millis();
if(TimNow < ExTimer ) {ExTimer=TimNow;}
if((TimNow - ExTimer) >= 100) {ExTimer=TimNow;ExcTimer();}
}
void ExcTimer(){//Esta funcion se ejecuta cada decima de segundo
CountMsg++;
if (CountMsg>=10){CountMsg=0;CountSg++;LoopNewSecond();}
if (CountSg>=30){Exc30Seg();CountSg=0;}
}
void LoopNewSecond(){}//eSTA SE EJECUTA CADA SEGUNDO
void Exc30Seg(){}//eSTA SE EJECUTA CADA 30 SG