I'm trying to use a float switch to receive alerts via Blynk when a water level drops, and when it rises again. The code I have been using has been working for when the float drops (button pressed) and I could get it to work when the water comes back up, but it gets stuck in a loop. I'm new to Arduino programming and I'm sure it's some simple error in the way I'm writing/modifying this code...
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "710a4af9b1d82412fa477705bf642c634";
char ssid[] = "SSID";
char pass[] = "PWD";
int flag=0;
void notifyOnButtonPress()
{
int isButtonPressed = digitalRead(D1); //assignment here for pin
if (isButtonPressed==1 && flag==0) {
Blynk.notify("Alert : Water Level has dropped");
flag=1;
}
else if (isButtonPressed==0 && flag==0)
Blynk.notify("Alert : Water level has risen");
{
flag=0;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup notification button on pin D1
pinMode(D1,INPUT_PULLUP);
timer.setInterval(16000L,notifyOnButtonPress);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
I believe the problem is in function notifyOnButtonPress.
flagvariable indicates if a message has been issued that the switch is turned on, low water level, or turned off, high water level?