Como puedo leer el estado del pin virtual desde el void loop?

Before creating the topic

  1. Search forum for similar topics
  2. Check http://docs.blynk.cc and http://help.blynk.cc/
  3. 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. :point_up: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.

  1. You don’t have a pinMode statement in your void setup for the led pin

  2. I think you’ll find that the onboard LED is active LOW, so lights whne you apply a LOW signal nopt a HIGH signal

  3. You don’t have an else option in your manual_mode logical test, so there’s no automatic functionality

  4. You haven’t specified a board type in your sketch, so it will use the custom board type in Settings.h and tis may conflict with the GPIO pins you’re using

  5. You can’t have `Blynk.run() from your void loop when using Blynk Edgent

  6. You’re missing two lines of firmware configuration from the top of your sketch

Pete.