Hi Blynkers !!
Apologies for my bad English…!!
First i want to say a very big and mega thank you for Blynk dev and creator.
I love this App, it’s a very great and usefull, who open and upgrade possibilities for a lot of differents electronic projects… Thx All !!!
But i’ve got a big question about how to trigger the value of a slider only when we push a button, anything like in this topic :
Button with slider
Unfortunately it doesn’t answerd my question.
I’m testing a lot of different method, with “Blynk.virtualWrite();” with “BLYNK_READ(){}”, with “Blynk.syncVirtual(V…);”.
But i never can use the “value= param.asInt();” of a BLYNK_WRITE(V2) like my slider, in an other BLYNK_WRITE(V1) like my button.
For example in the following code, the two BLYNK_WRITE are working good, but separatly, i would like to combine them, and i don’t know how… please can you help me ???
(in the following code i’m using ESP32 that’s why i’m using :“ledcWrite(ledChannel, X);” to remplace the analogWrite fonction.
I’m working in Bluetooth.
And i’ve just a LED connected to the Gpio 16.
And my objectif is to light on the LED only when i push the Button with the luminosity informed by the Slider.
My Blynk app use 3 Widget, one for the Bluetooth.
One for the Slider on V2 limited 0 to 255.
One for the Button on V1.)
// the number of the LED pin
const int ledPin = 16; // 16 corresponds to GPIO16
// setting PWM properties for use "ledcWrite" to replace "analogWrite"
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
// the int for my Slider value.
int dutyCycle ;
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleEsp32_BT.h>
char auth[] = "***********";
// My Button on V1 in my Blynk App.
BLYNK_WRITE(V1)
{
int ledPin = param.asInt();
if(ledPin==1){
dutyCycle = 250;
ledcWrite(ledChannel, dutyCycle);
}
else {
//dutyCycle = 0 ;
ledcWrite(ledChannel, LOW);
}
Serial.print("ledPin = ");
Serial.println(ledPin);
}
// My Slider on V2 in my Blynk App.
BLYNK_WRITE(V2)
{
int dutyCycle = param.asInt();
ledcWrite(ledChannel, dutyCycle);
Serial.print(" /// dutyCycle = ");
Serial.println(dutyCycle);
}
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
Serial.begin(9600);
Serial.println("Waiting for connections...");
Blynk.setDeviceName("Blynk");
Blynk.begin(auth);
}
void loop(){
Blynk.run();
timer.run();
}