Can someone give me a solution to the following problem?
I have 1 IR remote, blynk app,some pushButtons and also 1 relay module.
(I set 1 pin of ATMega as input to be able to read what esp sends when I use the blynk app).
So basically what I want to do is this:
If I press btn1 from the IR Remote or PushBtn nr1, or I send 1 from blynk app
then relay 1 must turn on. For now that part works.
Anyway, what I want to do next is this:
If the relay is turned on (closed) I want to be able to turn it off using the same buttons (for which I have set a counter and I call that variable).
Now I can turn the relay off only if I use the same btn that previously I have used to turn it on. But I want to be able to turn it off the other way.
If I used the blynk app to turn it on then if I press the pushbtn second time - I want it to be off. Also if I don't press the pushbtn but I use the IR remote and press 1 2 times- the relay should be off.
if(cntbtn2 == 1 || cntPushbtn2 == 1)
{
digitalWrite(rel2,LOW);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
if(cntbtn1 == 1 || cntPushbtn1 == 1)
{
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.aprinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOn);
}
else if(cntbtn1 != 1)
{
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.stinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOff);
}
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.aprinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOn);
}
else if(cntbtn2 == 2)
{
if(cntbtn1 == 1 || cntPushbtn1 == 1)
{
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.aprinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOn);
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.stinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOff);
}
else{
digitalWrite(rel2,HIGH);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.stinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOff);
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.stinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOff);
}
}
if(cntbtn2 == 1 && cntPushbtn2 == 2)
{
digitalWrite(rel2,HIGH);
}
//ecran stanga
if(cntbtn1 == 1 || digitalRead(espPin) == 1 || cntPushbtn1 == 1)
{
digitalWrite(rel1,LOW);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.aprinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOn);
if(cntbtn2 == 1 || cntPushbtn2 == 1)
{
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.aprinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOn);
}
else
{
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.stinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOff);
}
}
else if(cntbtn1 == 2)
{
digitalWrite(rel1,HIGH);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.stinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOff);
if(cntbtn2 == 1 || cntPushbtn2 == 1)
{
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.aprinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOn);
}
if(cntbtn2 != 1)
{
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.stinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOff);
}
}
else
{
digitalWrite(rel1,HIGH);
digitalWrite(rel2,HIGH);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(32,10,"Interior");
u8g.drawFrame(0,12,128,51);
u8g.drawLine(64,12,64,62);
u8g.setFont(u8g_font_5x8);
u8g.drawStr(10,23,"Sufragerie");
u8g.drawStr(15,60,"L.stinsa");
u8g.drawBitmapP( 20, 8, 16, 64, LightOff);
u8g.drawStr(73,23,"Dormitor");
u8g.drawStr(75,60,"L.stinsa");
u8g.drawBitmapP( 78, 7, 16, 64, LightOff);
}
}