Help reading virtual pins

Cant seem to read a virtual pin, what I am trying to do is have a slider determine if it will be automated or a turn on or turn off the led



#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "my authtoken";
int knap = 1;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "My Network";
char pass[] = "My Code";
int Lys = 0;
void setup()
{
  // Debug console
  Serial.begin(9600);
  
  Blynk.begin(auth, ssid, pass);
}



void loop(){

Blynk.run();
  Blynk.virtualWrite(V1, digitalRead(13));
  Blynk.virtualWrite(V2, digitalRead(1));
  Blynk.virtualWrite(V0, analogRead(A0));
  // Måske bliver analogread til digitalread
    int Lys = analogRead(A0);
         knap = Blynk.virtualRead(V1)

      if (knap  = 0){
        digitalWrite(13, LOW)
      }
      if (knap = 1) {
        digitalWrite(13, HIGH)
      }
      if (knap = 2) {

          if (Lys > 500){
              digitalWrite(13, HIGH);
              
            }
          else{
              digitalWrite(13, LOW);
          }

          
  }
}

  

you’ll probably want to read a bit more on how structure blynk code.

Your code structure is wrong. E.g. you void loop() should look like this:

void loop() {
  Blynk.run();
}

perhaps if you use a timer and over the air update this can become this:

void loop() {
  timer.run(); 
  Blynk.run();
  ArduinoOTA.handle();
}

but no more than that. Then the actions you need to take with blynk are created in separate functions. Have a look at the examples in the sketchbuilder

further sections you want to read up on are
BLYNK_WRITE and BLYNK_READ

1 Like