Hi, I have a problem with this sketch that I can’t really solve. The problem ONLY arises at startup. My goal is to create the reading of a series of errors in sequence, in practice the value of the writing in Blynk.virtualWrite(V2) is not updated WITH THE CURRENT ONE.
Example: if on startup the error was Blynk.virtualWrite(V2, “SENSOR NOT CONNECTED !”); , on the next boot, even though the error is still resolved and should show the next error, i.e. Blynk.virtualWrite(V2, “V.MIN WRONG !”);, this does NOT happen.
#define BLYNK_TEMPLATE_ID "MYCODE"
#define BLYNK_TEMPLATE_NAME "Test 8266"
#define BLYNK_FIRMWARE_VERSION "1.3.6"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
BlynkTimer timer;
int valoremin ;
byte FlagSensore = 0 ;
byte FlagVminErrato = 0 ;
byte FlagVmaxErrato = 0 ;
void setup() {
Serial.begin(115200);
BlynkEdgent.begin() ;
EEPROM.begin(512);
valoremin = 100 ;
timer.setInterval( 1000L, ValoriErrati ) ;
}
void ValoriErrati (){
Serial.println (valoremin);
Serial.print ("FlagSensore");Serial.println (FlagSensore);
Serial.print ("FlagVminErrato");Serial.println (FlagVminErrato);
if (analogRead(A0) <= 140 || analogRead (A0) >= 700) {
if (FlagSensore == 0 ) {
Blynk.virtualWrite (V2, "SENSORE NON COLLEGATO !");
FlagSensore = 1 ;
FlagVminErrato = 0 ;
FlagVmaxErrato = 0 ;
}}
else if (analogRead(A0) > 140 && analogRead (A0) < 700) {
if (FlagSensore == 1 ) {
FlagSensore = 0 ;
}}
if (valoremin < 150 || valoremin >= 190 ) {
if (FlagSensore == 0 && FlagVminErrato == 0 ){
//Blynk.setProperty (V2, "color", "#FF0000"); //RED
Blynk.virtualWrite (V2, "V.MIN ERRATO !");
FlagVminErrato = 1 ;
}}
else if (valoremin > 150 && valoremin < 190 ){
if (FlagVminErrato == 1){
FlagVminErrato = 0 ;
}}
}
void loop() {
BlynkEdgent.run();
timer.run();
}