Hi all,
Iām using a Node MCU v2 and Blynk to create a unique remote control for my house.
Everythink works pretty well and Iām able to control differente device like TV, DVD, HiFi and so on.
To keep the user interface simple I introduced a menu (bottom of UI) that select the device;
if TV is selected than the IR code sent from ON/OFF botton is the right one for TV; if you move from menu to DVD the same button (ON/OFF) will control the DVD player. ā¦and and everythink works fine.
Now, to complete my project I decided to introduce colors⦠The bottom menu everytime a device is selected move the color of active button to the dedicated color.
HERE A SCREENSHOT:
EX: TV is green and DVD is red.
If I select TV from device the ON/OFF button become green. If I select DVD the ON/OFF button became red. This is super helpfull in terms of usability.
Now I got a problem⦠I probably introduced to many call to Blynk and Iām frequently disconnected. (is it correct?)
I donāt think is a connection problem is this I need the <SimpleTimer.h>⦠I gave a look to https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino but I donāt understand very well how to implement it.
this is my code; where/how I have to implement the simple timer:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// IR remote
#include <IRremoteESP8266.h>
char auth[] = "ac0c58077892411bae46ed5cd4743f76";
SimpleTimer timer;
IRsend irsend(0); ///an IR led is connected to GPIO --> D4
// ======= SKETCH IR
int pinValueV1;
int pinValueV4;
int pinValueV5;
unsigned int ScreenUp[63] = {1400, 400, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1350, 400, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 1350, 400, 1350, 400, 1350, 400, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 1400, 400, 1400, 400, 1350, 400, 1350, 400, 500};
unsigned int ScreenDown[63] = {1400, 400, 1350, 400, 1400, 400, 1400, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1350, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 1400, 400, 550, 1200, 1350, 400, 1350, 400, 1400, 400, 550, 1200, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 1400, 400, 1400};
// ====== DEVICE SELECTOR
BLYNK_WRITE(V1) {
switch (param.asInt())
{
case 1: // Item 1 - TV LIVING
pinValueV1 = 1;
Blynk.setProperty(V2, "color", "#23C48E"); //GREEN
Blynk.setProperty(V4, "color", "#23C48E"); //GREEN
Blynk.setProperty(V5, "color", "#23C48E"); //GREEN
Blynk.setProperty(V6, "color", "#23C48E"); //GREEN
Blynk.setProperty(V7, "color", "#23C48E"); //GREEN
Blynk.setProperty(V13, "color", "#23C48E"); //GREEN
Blynk.setProperty(V14, "color", "#23C48E"); //GREEN
Blynk.setProperty(V15, "color", "#23C48E"); //GREEN
break;
case 2: // Item 2 - DVD
pinValueV1 = 2;
Blynk.setProperty(V2, "color", "#D3435C"); //RED POWER
Blynk.setProperty(V3, "color", "#D3435C"); //RED SOURCE
Blynk.setProperty(V3, "label", "HOME");
Blynk.setProperty(V4, "color", "#D3435C"); //RED SOURCE
Blynk.setProperty(V4, "label", "LEFT/RIGHT");
Blynk.setProperty(V5, "color", "#D3435C"); //RED SOURCE
Blynk.setProperty(V13, "color", "#D3435C"); //RED SOURCE
Blynk.setProperty(V15, "color", "#D3435C"); //RED SOURCE
break;
case 3: // Item 3 - AUX
pinValueV1 = 3;
Blynk.setProperty(V2, "color", "#04C0F8"); //BLU
Blynk.setProperty(V4, "color", "#04C0F8"); //BLU
delay(1000);
break;
case 4:
pinValueV1 = 4;
break;
case 5: // Item 5 - Projector Screen
pinValueV1 = 5;
Blynk.setProperty(V15, "color", "#ED9D00"); //YELLOW
break;
}
}
// ========== END DEVICE SELECTOR
BLYNK_WRITE(V2) // ON/OFF
{
if ( param.asInt() && pinValueV1 == 1 ) // ON/OFF TV
{ irsend.sendNEC(0xFB38C7, 32);
} else if ( param.asInt() && pinValueV1 == 2 ) // ON/OFF DVD
{ irsend.sendSAMSUNG(0xB4B40CF3, 32);
} else if ( param.asInt() && pinValueV1 == 3 ) // ON/OFF AUX
{ irsend.sendNEC(0x7E8154AB, 32);
}
}
BLYNK_WRITE(V3) // SOURCE
{
if ( param.asInt() && pinValueV1 == 1 )
{ irsend.sendNEC(0xFBE817, 32); //
} else if ( param.asInt() && pinValueV1 == 2 ) // SAMSUNG
{ irsend.sendSAMSUNG(0xB4B4E619, 32);
}
}
BLYNK_WRITE(V4) // AUDIO + / -
{
pinValueV4 = V4 ;
if ( param.asInt() == 4 && pinValueV1 == 1 )
{ irsend.sendNEC(0xFBD22D, 32); // + AUDIO
} else if ( param.asInt() == 3 && pinValueV1 == 1 )
{ irsend.sendNEC(0xFBF20D, 32); // - AUDIO
} else if ( param.asInt() == 3 && pinValueV1 == 3 ) // AUDIO AUX -
{ irsend.sendNEC(0x5EA1D827, 32); // - AUDIO
} else if ( param.asInt() == 3 && pinValueV1 == 3 ) // AUDIO AUX +
{ irsend.sendNEC(0x5EA158A7, 32); // - AUDIO
} else if ( param.asInt() == 3 && pinValueV1 == 2 ) // DVD Left
{ irsend.sendSAMSUNG(0xB4B49A65, 32); // - AUDIO
} else if ( param.asInt() == 3 && pinValueV1 == 2 ) // DVD Right
{ irsend.sendSAMSUNG(0xB4B45AA5, 32); // - AUDIO
}
}
BLYNK_WRITE(V5) // CHANNELS + / -
{
pinValueV5 = V5 ;
if ( param.asInt() == 4 && pinValueV1 == 1 )
{ irsend.sendNEC(0xFB906F, 32); // + CH
} else if ( param.asInt() == 3 && pinValueV1 == 1 )
{ irsend.sendNEC(0xFBA05F, 32); // - CH
} else if ( param.asInt() == 3 && pinValueV1 == 2 ) // DVD CH -
{ irsend.sendSAMSUNG(0xB4B41EE1, 32); // - CH
} else if ( param.asInt() == 4 && pinValueV1 == 2 ) // DVD CH +
{ irsend.sendSAMSUNG(0xB4B4EE11, 32); // - CH
}
}
BLYNK_WRITE(V6) // TXT
{
if ( param.asInt() && pinValueV1 == 1 )
{ irsend.sendNEC(0xFB807F, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V7) // INFO
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendNEC(0xFB1AE5, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V8) // Rewind
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendSAMSUNG(0xB4B44CB3, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V9) // Play
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendSAMSUNG(0xB4B48C73, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V10) // Stop
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendSAMSUNG(0xB4B49C63, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V11) // Forward
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendSAMSUNG(0xB4B44CB3, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V12) // Eject
{
if ( param.asInt() && pinValueV1 == 2 )
{ irsend.sendSAMSUNG(0xB4B46C93, 32); //
} else {
//LOW - OFF
}
}
BLYNK_WRITE(V13) // OK
{
if ( param.asInt() && pinValueV1 == 1 )
{ irsend.sendNEC(0xFB609F, 32); //
} else if ( param.asInt() && pinValueV1 == 2 ) // SAMSUNG
{ irsend.sendSAMSUNG(0xB4B41AE5, 32);
}
}
BLYNK_WRITE(V14) // KO
{
if ( param.asInt() && pinValueV1 == 1 )
{ irsend.sendNEC(0xFB50AF, 32); //
} else {
// LOW - OFF
}
}
BLYNK_WRITE(V15) // UP/DOWN-
{
pinValueV5 = V15 ;
if ( param.asInt() == 4 && pinValueV1 == 1 ) //+ CH
{ irsend.sendNEC(0xFB58A7, 32); //
} else if ( param.asInt() == 3 && pinValueV1 == 1 ) // - CH
{ irsend.sendNEC(0xFB12ED, 32); //
} else if ( param.asInt() == 3 && pinValueV1 == 2 ) // DVD UP
{ irsend.sendSAMSUNG(0xB4B4E21D, 32); //
} else if ( param.asInt() == 4 && pinValueV1 == 2 ) // DVD DOWN
{ irsend.sendSAMSUNG(0xB4B412ED, 32); //
} else if ( param.asInt() == 3 && pinValueV1 == 5 ) // SCREEN UP
{ irsend.sendRaw(ScreenUp, 63, 32);
} else if ( param.asInt() == 4 && pinValueV1 == 5 ) // SCREEN DOWN
{ irsend.sendRaw(ScreenDown, 63, 32);
}
}
// ========LOOP
void setup()
{
Serial.begin(9600);
irsend.begin();
Blynk.begin(auth, "A....io", "x----");
//Blynk.begin(auth, "N------1", "k.....");
Blynk.syncAll();
}
void loop()
{
Blynk.run();
timer.run();
}