Hi All,
I’m new to Blynk but I like it
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]