Qualcuno sarebbe così gentile da farmi capire bene come funziona questa libreria?
Ho fatto diverse prove ma essuna mi da il risultato che voglio.
ho dichiatato 2 intervalli:
// funzione che viene richiamata continuamente
void timer5m () {
Serial.print("SILENZIO L'ALLARME ogni 30 secondi\t");
Silenzia = true;
interval = 150;
Serial.println("timer5m attivo\t");
}
// funzione che viene richiamata una sola volta
void timer1h() {
Serial.println("DISATTIVO PER UNA SOLA VOLTA TUTTI GLI ALLARMI COMPRESO QUELLO DEI 30 SECONDI");
StoredAlert = true;
AlertBuzzer = false;
Serial.println("timer1h attivo\t");
interval = 500;
}
poi nel setup
void setup() {
// put your setup code here, to run once:
timer.setInterval(30000, timer5m); //Riattivo l'allarme ogni 5 minuti
timer.setInterval(90000, timer1h); //Disattivo per una sola volta l'allarme dopo 1 ora
}
e nel loop
void loop()
{
Temp_Min_Stored = EEPROM.read(EEPROM_Address_MIN_INT) + (EEPROM.read(EEPROM_Address_MIN_DEC) * 0.01); //costruzione setpoin temperatura dai dati letti dall'EEPROM
Temp_Max_Stored = EEPROM.read(EEPROM_Address_MAX_INT) + (EEPROM.read(EEPROM_Address_MAX_DEC) * 0.01); //costruzione setpoin temperatura dai dati letti dall'EEPROM
temperature(); //Leggo le temperature
// Impostazione delle azioni temporizzate
//#define wd_timer_id timer.setInterval(60000, wdCallback) //Disattivo definitivamente l'allarme dopo 1 ora
timer.setInterval(30000, timer5m); //Riattivo l'allarme ogni 5 minuti
timer.setInterval(90000, timer1h); //Disattivo per una sola volta l'allarme dopo 1 ora
// example for init screen
if ((millis() - g_lcdml_initscreen) >= _LCDML_DISP_cfg_initscreen_time)
{
g_lcdml_initscreen = millis(); // reset init screen time
LCDML_DISP_jumpToFunc(LCDML_FUNC_initscreen); // jump to initscreen
}
Serial.print("Stampo da loop StoredAlert\t"); Serial.println(StoredAlert);
if (!StoredAlert)
{
Serial.print("Stampo da loop if !StoredAlert la variabile StoredAlert\t"); Serial.println(StoredAlert);
timer.run(); // qui è dove si verifica il 'polling' della libreria SimpleTimer
int timerId1 = timer.setInterval(30000, timer5m); //Riattivo l'allarme ogni 5 minuti
int timerId2 = timer.setInterval(90000, timer1h); //Disattivo per una sola volta l'allarme dopo 1 ora
//timer.disable(timerId1); // Disables the specified timer
//timer.disable(timerId2); // Disables the specified timer
//=================================== VERIFICO SE LA TEMPERATURA E' TROPPO BASSA =========================================
while (tempDALLAS < (Temp_Min_Stored))
{
temperature();
Temp_Min_Stored = EEPROM.read(EEPROM_Address_MIN_INT) + (EEPROM.read(EEPROM_Address_MIN_DEC) * 0.01);
//Serial.print ("Temp_Min_Stored = "); Serial.println (Temp_Min_Stored);
u8g2.firstPage();
do {
digitalWrite (led_green, LOW ); //set the LED off
digitalWrite (led_red, HIGH); //set the LED on
/* Serial.println();
Serial.print("Temperatura acqua troppo BASSA! ");
Serial.println(tempDALLAS);
Serial.print("StoredAlert\t"); Serial.println(StoredAlert);
Serial.print("Tacita\t"); Serial.println(Tacita);
*/
pulsante ();
allarme();
//timer.enable(timerId1); // Disables the specified timer
//timer.enable(timerId2); // Disables the specified timer
u8g2.drawStr(5, 10, "ArduAcquario MALAWI");
u8g2.drawStr(35, 25, "Alert!");
u8g2.drawStr(0, 38, "Temperatura Acquario");
u8g2.drawStr(20, 51, "TROPPO BASSA!");
u8g2.setCursor(40, 63);
u8g2.print(tempDALLAS);
u8g2.drawStr (70, 63, "\260 C");
delay(5);
} while (u8g2.nextPage() ); //end while (u8g2.nextPage() )
} //end while (tempDALLAS < (Temp_Min_Stored))
//================================== VERIFICO SE LA TEMPERATURA E' TROPPO ALTA =========================================
while (tempDALLAS > (Temp_Max_Stored))
{
temperature(); //Leggo le temperature
Temp_Max_Stored = EEPROM.read(EEPROM_Address_MAX_INT) + (EEPROM.read(EEPROM_Address_MAX_DEC) * 0.01);
// Serial.print ("Temp_Max_Stored = "); Serial.println (Temp_Max_Stored);
u8g2.firstPage();
do {
digitalWrite (led_green, LOW ); //set the LED off
digitalWrite(relay_pin, LOW);
/* Serial.println();
Serial.print("Temperatura acqua troppo ALTA! ");
Serial.println(tempDALLAS);
Serial.print("StoredAlert\t"); Serial.println(StoredAlert);
Serial.print("Tacita\t"); Serial.println(Tacita);
*/
pulsante ();
allarme();
// timer.enable(timerId1); // Disables the specified timer
// timer.enable(timerId2); // Disables the specified timer
u8g2.drawStr(5, 10, "ArduAcquario MALAWI");
u8g2.drawStr(35, 25, "Alert!");
u8g2.drawStr(0, 38, "Temperatura Acquario");
u8g2.drawStr(20, 51, "TROPPO ALTA!");
u8g2.setCursor(40, 63);
u8g2.print(tempDALLAS);
u8g2.drawStr (70, 63, "\260 C");
digitalWrite(relay_pin, LOW);
delay(5);
} while (u8g2.nextPage() ); //end do While
}//END While //(tempDALLAS > (Temp_Max_Stored))
led_color = led_green;
interval = 500;
led();
} //end if (!StoredAlert)
else
{
digitalWrite (led_green, HIGH ); //set the LED on
digitalWrite (led_red, LOW); //set the LED off
}//end else (!StoredAlert)
digitalWrite(relay_pin, HIGH);
noTone(buzzer);
Silenzia = false;
// this function must called here, do not delete it
LCDML_run(_LCDML_priority);
// example for init screen
if ((millis() - g_lcdml_initscreen) >= _LCDML_DISP_cfg_initscreen_time) {
g_lcdml_initscreen = millis(); // reset init screen time
LCDML_DISP_jumpToFunc(LCDML_FUNC_initscreen); // jump to initscreen
}
// this function must called here, do not delete it
LCDML_run(_LCDML_priority);
} //END void Loop
void allarme()
{
led_color = led_red;
if ((Silenzia) || (Tacita) || (StoredAlert))
{
led();
}
else digitalWrite (led_red, HIGH); //set the LED on
if (!Silenzia)
{
if ((Tacita) || (StoredAlert))
{
noTone(buzzer);
}
else if (outputTone) {
//We are currently outputting a tone
//Check if it's been long enough and turn off if so
if (millis() - previousMillisAlarm >= noteDuration)
{
previousMillisAlarm = millis();
noTone(buzzer);
outputTone = false;
}
}
else {
//We are currently in a pause
//Check if it's been long enough and turn on if so
if (millis() - previousMillisAlarm >= pauseBetweenNotes)
{
previousMillisAlarm = millis();
tone(buzzer, 1, 1000);
outputTone = true;
}
}
} //END if ((!Silenzia) )
else if (Silenzia)
{
noTone(buzzer); //non suona
if (millis() - previousMillisAlarm >= snoozeDuration)
{
Silenzia = false;
previousMillisAlarm = millis();
}
} //end else if (Silenzia)
} //END allarme()
ciò che voglio è che il buzzer si silenzi da solo dopo 30 secondi e dopo 90 secondi si taciti definitivamente settando su true una variabile boolean StoredAlert che impedisce al buzzer di suonare.
Fin qui nessun problema.
Quando però con un menù imposto la variabile StoredAlert su false il timer non si riavvia da capo ma in un lasso di tempo che non riesco a capire. A volte si trova nella void dei 30 secondi a volte parte subito con quella dei 90 secondi tacitando tutto da subito.
Ciò che non riesco a fare è sospendere il timer e riavviarlo da ZERO quando StoredAlert = false e il buzzer si trova nello stato di allarme.