Hello. Can anyone help me with this problem. I have a light that I want to turn on when a sensor is triggered, but also if a button from the app is pushed. Also to see in the app is the light is on or off and if it is on to get a notification. The button is V0, and V2 is the sensor. Now the light is turning on if the sensor is triggerd but if I push the button from the app the light goes fast on-off.
This is what I have so far.
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "***";
char pass[] = "***";
BlynkTimer timer;
int LightS=35;
int LightR=2;
BLYNK_WRITE(V0)
{
int LightV = param.asInt();
digitalWrite(LightR,LightV);
}
void sendSensor()
{
int LightV=analogRead(LightS);
Blynk.virtualWrite(V2,LightV);
if (V0 == 0) {
if (LightV < 1) {
digitalWrite(LightR,HIGH);
Blynk.virtualWrite(V0,1);
} else {
digitalWrite(LightR,LOW);
Blynk.virtualWrite(V0,0);
}
}
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(2,OUTPUT);
timer.setInterval(1000L, sendSensor);
delay(100);
}
void loop() {
Blynk.run();
timer.run();
}