helo i want to ask if i can lock buttons on my Blynk app when my device is Offline because if i press the button when my device is offline when i connect it it starts all buttons tha i press earlier…Is any way to lock the buttons when device is offline?
BLYNK_WRITE(V1) //Virtual pin of button widget (V1)
{
int state = param.asInt();
if (state) {
// your code
EEPROM.write(0, HIGH);
}
else
{
//your code
EEPROM.write(0, LOW);
}
}
bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect) {
if (EEPROM.read(0) == HIGH) {
Blynk.virtualWrite(V1, HIGH); //switch on your button widget
}
else
{
Blynk.virtualWrite(V1, LOW); //switch off your button widget
}
isFirstConnect = false;
}
In this way, the button switch on or off at the reconnection depending on the last state stored in eeprom when you are connected.
Furthermore, you haven’t to set syncVirtual(V1) at the first connection.
I hope my suggest is correct
I acctualy work with puss buttons and digital pins with a small delay…this works also and for puss buttons? and thanks for your help I’ll try it when i have time and it will helpfull if you make more comments because i’m new on alla this programming
> #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
> #include <SPI.h>
> #include <Ethernet.h>
> #include <BlynkSimpleEthernet.h>
> char auth[] = " auth code here";
> const int porta1 = 7;
> const int porta2 = 3;
> const int mpagazi =6;
> const int diakoptis =5;
> int btn1 = 1;
> int btn2 = 1;
> int btn3 = 1;
> WidgetLED led1 (V2);
> WidgetLED led2 (V3);
> WidgetLED led3 (V4);
> WidgetLED led4 (V5);
> void setup()
> {
> pinMode (porta1, OUTPUT);
> pinMode (porta2, OUTPUT);
> pinMode (mpagazi, OUTPUT);
> pinMode (diakoptis, OUTPUT);
> digitalWrite (porta1, HIGH);
> digitalWrite (porta2, HIGH);
> digitalWrite (mpagazi, HIGH);
> digitalWrite (diakoptis, HIGH);
> Blynk.begin(auth);
> }
> void loop()
> {
> //diakoptis status
> if (digitalRead (diakoptis) == 0) {
> led4.on();
> }
> else {
> led4.off();
> }
> // porta1 status
> if (digitalRead (porta1) == 0 ) {
> if (btn1 == 1) {
> led1.on();
> btn1 = 0;
> }
> else if (btn1 == 0){
> led1.off();
> btn1 = 1;
> }
> }
> //porta2 status
> if (digitalRead (porta2) == 0 ) {
> if (btn2 == 1) {
> led2.on();
> btn2 = 0;
> }
> else if (btn2 == 0){
> led2.off();
> btn2 = 1;
> }
> }
> //mpagazi status
> if (digitalRead (mpagazi) == 0 ) {
> if (btn3 == 1) {
> led3.on();
> btn3 = 0;
> }
> else if (btn3 == 0){
> led3.off();
> btn3 = 1;
> }
> }
>
> Blynk.run();
> }
it’s just blynk code thats just told me when the relays open or closed with a virtual led on my app
I don’t understand. Is this the full code or not? I don’t read the part of code about Button widget
However, i know that when you use blynk in your project, One of the most important rule is to use simpletimer library in order to delete delays and to have only blynk.run in void loop()
it’s only an example of blynk and i put only some if to check if the pins is HIGH or LOW and light a virtual led on mu app …anyway thanks for your time