Set multiple sliders to zero with button

Hi All,

I’m new to Blynk but I like it :slight_smile:

My first project is controlling 433MHZ socket from Blynk. I got it all working, a local Blynk server, an app and an ESP8266 with a 433 transmitter attached. The complete code is below

However, I have a question about the app/interface.

I have 8 sliders to control my 433 sockets. The sliders send 0 or 1 to my code to switch the sockets on/off
But I also have one button to switch everything off. When I use this button my sockets are indeed switched off. The sliders however stay in their position. When I hit this button I would like to set all sliders to zero.

I there a way this can be done ?

Thanks in advance !

The app/interface looks something like this:

[code]
1----oo---- 2----oo---- <<sliders
3----oo---- 4----oo----
5----oo---- 6----oo----
7----oo---- 8----oo----

All off <<button[/code]

The complete code:

[code]//#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <RCSwitch.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon) and have the server mail it to you.
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

// WiFi settings.
char ssid[] = “xxxxxx”;
char pass[] = “xxxxxxxxxxx”;
char server[]=“192.168.1.xxx”;

//new RCSwitch instance called “transmitter”
RCSwitch transmitter = RCSwitch();

//constants that hold the code to be transmitted to switch the sockets ON and OFF:
const long A1_ON = 328981;
const long A1_OFF = 328980;
const long A2_ON = 345365;
const long A2_OFF = 345364;

const long B1_ON = 4523285;
const long B1_OFF = 4523284;
const long B2_ON = 4539669;
const long B2_OFF = 4539668;

const long C1_ON = 1377557;
const long C1_OFF = 1377556;
const long C2_ON = 1393941;
const long C2_OFF = 1393940;

const long D1_ON = 5571861;
const long D1_OFF = 5571860;
const long D2_ON = 5588245;
const long D2_OFF = 5588244;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, server);

// Transmitter is connected to Pin #12
transmitter.enableTransmit(12);

// Optional set number of transmission repetitions.
transmitter.setRepeatTransmit(5);

//At startup all sockets should be turned off
// transmitter.send(A1_OFF, 24);
// transmitter.send(A2_OFF, 24);
// transmitter.send(B1_OFF, 24);
// transmitter.send(B2_OFF, 24);
// transmitter.send(C1_OFF, 24);
// transmitter.send(C2_OFF, 24);
// transmitter.send(D1_OFF, 24);
// transmitter.send(D2_OFF, 24);

}

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

// The functions below will be called every time the App writes value 1 to Virtual Pin VX (V1, V2, V3, etc…)

// Virtual pins:
//All OFF = V0
//A1 = V1
//A2 = V2
//B1 = V3
//B2 = V4
//C1 = V5
//C2 = V6
//D1 = V7
//D2 = V8

/////////////////////////////////////////////
//ALL OFF
//when a button sends a write to virtual pin 0 every socket is turned OFF
BLYNK_WRITE(V0)
{
transmitter.send(A1_OFF, 24);
transmitter.send(A2_OFF, 24);
transmitter.send(B1_OFF, 24);
transmitter.send(B2_OFF, 24);
transmitter.send(C1_OFF, 24);
transmitter.send(C2_OFF, 24);
transmitter.send(D1_OFF, 24);
transmitter.send(D2_OFF, 24);
}

/////////////////////////////////////////////
//A1
BLYNK_WRITE(V1)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(A1_OFF, 24);
}else{
transmitter.send(A1_ON, 24);
}
}

/////////////////////////////////////////////
//A2
BLYNK_WRITE(V2)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(A2_OFF, 24);
}else{
transmitter.send(A2_ON, 24);
}
}

/////////////////////////////////////////////
//B1
BLYNK_WRITE(V3)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(B1_OFF, 24);
}else{
transmitter.send(B1_ON, 24);
}
}

/////////////////////////////////////////////
//B2
BLYNK_WRITE(V4)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(B2_OFF, 24);
}else{
transmitter.send(B2_ON, 24);
}
}

/////////////////////////////////////////////
//C1
BLYNK_WRITE(V5)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(C1_OFF, 24);
}else{
transmitter.send(C1_ON, 24);
}
}

/////////////////////////////////////////////
//C2
BLYNK_WRITE(V6)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(C2_OFF, 24);
}else{
transmitter.send(C2_ON, 24);
}
}

/////////////////////////////////////////////
//D1
BLYNK_WRITE(V7)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(D1_OFF, 24);
}else{
transmitter.send(D1_ON, 24);
}
}

/////////////////////////////////////////////
//D2
BLYNK_WRITE(V8)
{
if(param.asInt() == 0){
// switch OFF
transmitter.send(D2_OFF, 24);
}else{
transmitter.send(D2_ON, 24);
}
}[/code]

You would use the Blynk.virtualWrite(vPin, value) to do that. In the case of a slider you can move it around to match the action or a real slider (e.g. linear resistor ) if you wanted. This command, and others, let you change status, colour, and indication of various widgets.

In your case your would make a function that would be called when a button was pushed, then in that function move each slider to 0.

BLYNK_WRITE(vPIN) {  // set the V pin to match that of you button widget
Blynk.virtualWrite(V0, 0)  // set the V pin to match that of the slider, and then the value (position) of that slider
Blynk.virtualWrite(V1, 0)
Blynk.virtualWrite(V2, 0)
// and so on
}

Ok, thanks !

Found that I can also use this on 0/1 buttons, makes more sense then using a slider.
Better to use buttons too, the sliders don’t go all the way left (only just halfway until the 0 threshold is reached).

The slider widget is just a virtual tool, you can easily map it to whatever value you want in your code.

BLYNK_WRITE(vPIN) {  // set the V pin to match that of your slider widget
x = param.asInt();  // get slider value
y = map(x, 0, 255, -128, 128);  /map slider value to required range
}

I think (off the top of my head) that this will do the same thing, only more compact code.

BLYNK_WRITE(vPIN) {  // set the V pin to match that of your slider widget
y = map(param.asInt(), 0, 255, -128, 128);  //map slider value to required range
}

And then the same for sending data to the slider…

BLYNK_WRITE(vPIN) {  // set the V pin to match that of you button widget
Blynk.virtualWrite(V0, map(x -128, 128, 0, 255))  // set the V pin to match that of the slider, and then the value (position) of that slider
}

Thanks for your feedback Gunner,

I used buttons instead of slider and everything works like I wanted it to :slight_smile:
But good to know how to control a slider from the hardware code.

Below is the code that I uploaded to the final ESP Huzzah board to control my RF sockets.

[code]#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <RCSwitch.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon) and have the server mail it to you.
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxx”;

// WiFi settings:
char ssid[] = “XXXXXXXXXX”;
char pass[] = “XXXXXXXXXX”;
//The address of the local Blynk server:
char server[]=“192.168.1.XXX”;

//new RCSwitch instance called “transmitter”
RCSwitch transmitter = RCSwitch();

//constants that hold the code to be transmitted to switch the sockets ON and OFF:
const long A1_ON = 328981;
const long A1_OFF = 328980;
const long A2_ON = 345365;
const long A2_OFF = 345364;

const long B1_ON = 4523285;
const long B1_OFF = 4523284;
const long B2_ON = 4539669;
const long B2_OFF = 4539668;

const long C1_ON = 1377557;
const long C1_OFF = 1377556;
const long C2_ON = 1393941;
const long C2_OFF = 1393940;

const long D1_ON = 5571861;
const long D1_OFF = 5571860;
const long D2_ON = 5588245;
const long D2_OFF = 5588244;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, server);

// Transmitter is connected to Pin #12
transmitter.enableTransmit(12);

// Optional set number of transmission repetitions.
transmitter.setRepeatTransmit(5);

}

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

// The functions below will be called every time the App sends a value (0 or 1) to Virtual Pin VX (V1, V2, V3, etc…)
// the function use the parameter (0 or 1) to determine wether to send the ON or OFF signal

// Virtual pins:
//switch All OFF = V0
//switch A1 = V1
//switch A2 = V2
//switch B1 = V3
//switch B2 = V4
//switch C1 = V5
//switch C2 = V6
//switch D1 = V7
//switch D2 = V8

/////////////////////////////////////////////
//ALL OFF
//when a button sends a write to virtual pin 0 every socket is turned OFF
BLYNK_WRITE(V0)
{
//send the OFF signal to the wall socket:
transmitter.send(A1_OFF, 24);
//send a command to the app to set the button to zero state:
Blynk.virtualWrite(V1, 0);

transmitter.send(A2_OFF, 24);
Blynk.virtualWrite(V2, 0);

transmitter.send(B1_OFF, 24);
Blynk.virtualWrite(V3, 0);
transmitter.send(B2_OFF, 24);
Blynk.virtualWrite(V4, 0);

transmitter.send(C1_OFF, 24);
Blynk.virtualWrite(V5, 0);
transmitter.send(C2_OFF, 24);
Blynk.virtualWrite(V6, 0);

transmitter.send(D1_OFF, 24);
Blynk.virtualWrite(V7, 0);
transmitter.send(D2_OFF, 24);
Blynk.virtualWrite(V8, 0);

}

/////////////////////////////////////////////
//A1
BLYNK_WRITE(V1)
{
//if the parameter that is sent by the button: param.asInt() == 1
if(param.asInt()){
// switch ON
transmitter.send(A1_ON, 24);
//if it is not 1 then it is 0
}else{
//switch OFF
transmitter.send(A1_OFF, 24);
}
}

/////////////////////////////////////////////
//A2
BLYNK_WRITE(V2)
{
if(param.asInt()){
transmitter.send(A2_ON, 24);
}else{
transmitter.send(A2_OFF, 24);
}
}

/////////////////////////////////////////////
//B1
BLYNK_WRITE(V3)
{
if(param.asInt()){
transmitter.send(B1_ON, 24);
}else{
transmitter.send(B1_OFF, 24);
}
}

/////////////////////////////////////////////
//B2
BLYNK_WRITE(V4)
{
if(param.asInt()){
// switch OFF
transmitter.send(B2_ON, 24);
}else{
transmitter.send(B2_OFF, 24);
}
}

/////////////////////////////////////////////
//C1
BLYNK_WRITE(V5)
{
if(param.asInt()){
transmitter.send(C1_ON, 24);
}else{
transmitter.send(C1_OFF, 24);
}
}

/////////////////////////////////////////////
//C2
BLYNK_WRITE(V6)
{
if(param.asInt()){
transmitter.send(C2_ON, 24);
}else{
transmitter.send(C2_OFF, 24);
}
}

/////////////////////////////////////////////
//D1
BLYNK_WRITE(V7)
{
if(param.asInt()){
transmitter.send(D1_ON, 24);
}else{
transmitter.send(D1_OFF, 24);
}
}

/////////////////////////////////////////////
//D2
BLYNK_WRITE(V8)
{
if(param.asInt()){
transmitter.send(D2_ON, 24);
}else{
transmitter.send(D2_OFF, 24);
}
}
[/code]