Blynk_write functions


I making a project on esp32 in arduino where i want to control diode on two mode by wifi. first mode
where i just on/off it by button (on virtual pin V1) - BLYNK_WRITE(V1)
and second mode where i control brightness by slider but , I want to in second mode so that the slider control is possible when I activate the button that allows it . - BLYNK_WTRITE(V2)

If someone could help me with that I wolud be very greatful


// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME           "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

Blynk_Write(V1) // first mode where i just switch on/off diode
 int pinValue = param.asInt()'
digital(13, pinValue);

BLYNK_WRITE(V2) // here is a second mode where i control brightness by slider 

// i don't know how to add button so that the slider can only be controlled when is pressed a button 


  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Blynk.virtualWrite(V1, pinValue); // by this line i see on gauge how bright it's
  Serial.print("V0 Slider value is: ");

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

void loop()
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

I’ ll be very greatful if someone could help me with that. :slight_smile:
~ fil

Hey there, please edit your post and add triple backticks ( ``` ) before and after your sketch.

According to this, V1 is an On/Off widget, not a gauge…

I think you’d be better simplifying your code to begin with, so you simply have a slider on your dashboard. If you want to also display the slider value then simply attach a display widget of some type (a gauge if you like) to the same virtual pin.

This line of code…

looks like it came from an ESP8266 sketch.
The ESP 32 doesn’t use analogWrite in the same way as the ESP8266, you should use the ledcSetup ledcAttachPin and ledcWrite commands, and avoid using pin numbers with a “D” prefix. Just use the GPIO number of the pin you are controlling instead.

This might be a good starting point…

If you use 6-bit resolution then your slider needs to go from 0 (off) to 255 (maximum brightness).
The datasteam you are using for this also needs to have the same range.


1 Like