Before creating the topic
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code.
Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
estoy haciendo un proyecto que tiene dos modo automatico y manual. el automatico se activa con un switch el pin virtual V0, y de ahi dependiendo los sensores de va ejecutando las demas salidas. y el manual cada salida es controlada por switch indivudaules. el problema esque no puedo leer el estado del pin virtual V0 para que en el voip loop entre en modo automatico
Well first of all, you shouldn’t be doing this type of logic test in the void loop. It should be done in a function which is called using a BlynkTimer, as explained here…
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
The solution to your problem is to use the BLYNK_WRITE(V0) callback function for set a GLOBAL variable to indicate whether you are in automatic or manual mode, something like thos…
boolean manual_mode = false; // declare the global variable and set it to false by default
BLYNK_WRITE(V0)
{
manual_mode = param.asInt();
}
You can then do a logical test in an if
statement within your timed function to decide whether to execute the code that’s associated with manual mode or the code that’s associated with automatic mode.
Pete.
lo hice pero por alguna razón no me permite leer el valor estando en otra la otra función temporizada.
hice lo que le entendí como para una prueba, donde conecte un sensor para ver si se enviaba la información cada segundo y eso si sale, pero cuando activo el switch v0 el manual_mode, no lo lee en la función temporizada
#include "BlynkEdgent.h"
BlynkTimer timer;
int led = 2;
int ldr = 34;
int luz = 0;
int ldr_luz = 0;
int manual_mode = 0;
void setup()
{
Serial.begin(115200);
BlynkEdgent.begin();
timer.setInterval(1000L, sensorDataSend);
}
void loop() {
BlynkEdgent.run();
Blynk.run();
timer.run();
}
void sensorDataSend()
{
ldr_luz = analogRead(ldr);
luz = -0.0244*ldr_luz +99.918;
Blynk.virtualWrite(V3,luz);
if(manual_mode == 1){
digitalWrite(led,HIGH);
}
}
BLYNK_WRITE(V0){
manual_mode = param.asInt();
}
deberia encender el led de la esp cuando activo el switch v0 pero no ocurre.