After pressing the button (V4) it does not turn on the pin (D5)
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#include <Simpletimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
int value = V4;
int prz = D5;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V4);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(prz, OUTPUT);
digitalWrite(prz, HIGH);
}
BLYNK_WRITE(value)
{
value = param.asInt();
if ( value == 1 )
{
digitalWrite(prz,LOW);
}
}
void loop()
{
Blynk.run();
}
This is a bit of a weird thing to do…
and the repeated use of value
for two different things is also wrong, as it means that when you get a 1 or a 0 (on or off) from your switch widget your BLYNK_WRITE(value)
command turns into BLYNK_WRITE(1)
or BLYNKI_WRITE(0)
so you’re no longer monitoring the widget attached to pin V4…
Try this instead…
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char ssid[] = "";
char pass[] = "";
#define vpin V4
#define prz D5
BLYNK_CONNECTED()
{
Blynk.syncVirtual(vpin);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(prz, OUTPUT);
digitalWrite(prz, HIGH);
}
BLYNK_WRITE(vpin)
{
digitalWrite(prz,!param.asInt());
}
void loop()
{
Blynk.run();
}
Pete.
1 Like