Help me with not updating button state

Ok I’m writing your code to see where is the bug :smile:

1 Like

That works for me :

void checkPhysicalButton()
{
  if (digitalRead(P1) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {

      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      if(ledState==0){
      Blynk.virtualWrite(V2 , LOW);
      }else{
       Blynk.virtualWrite(V2 , HIGH);
      }
    }
    btnState = LOW;
  } else {
    btnState = HIGH;
 // Update Button Widget
     
  }
}

okay flashing it, and i want to show you this.
in phone app it works on GPIO ( digital ) GP0,
Not virtual.

getting this error now…

error: ‘P1’ was not declared in this scope; did you mean ‘y1’?
98 | if (digitalRead(P1) == LOW) {
| ^~
| y1
exit status 1
‘P1’ was not declared in this scope; did you mean ‘y1’?

Yes replace P1 by btnPin :stuck_out_tongue_winking_eye:
But V2 can’t work because you have select digitalPin instead of virtualPin :smile:
2021-06-11_181008

Thats why im telling you…it is working on digitalpin…nothing works if i select V2

Maybe you should look at your previous post…

Pete.

2 Likes

yeah i have seen it but it was posted before fixing the button sync issue.

You can’t control V2 if it isn’t a virtual button

1 Like

Still no luck its not working…
we need to look somewhere else… look at the url it is working with D0 “”“oT5y/update/D0?value=0"”" not with V2.

God!!! :frowning:

Maybe the Sketch Builder “Sync Physical button” example is where you should start,

Pete.

2 Likes

@ [Blynk_Coeur]

Man it started to pick on V2 but the problem is " button states changes for a mili sec and goes back to off :confused:

The problem is here …
I think you have to start from scratch :smile:

EEEEEEHAAA!!! WE SOLVED IT MAN

i removed the line

Blynk.virtualWrite(V2, millis() / 1000); // Send UpTime seconds to App

Its working now…tell me how do i buy you a coffee ? :smiley:

1 Like

:shushing_face:

1 Like

why shhhhh ? :smile:
let others taste the fruit of our tree.

Ok I just saw that :dizzy_face:

Blynk.virtualWrite(V2, millis() / 1000);  // Send UpTime seconds to App


1 Like

Comon DM me, i really need to say thanks to you.
Because you made my smart farmhouse project completed because i need lots of these.

1 Like
Blynk.virtualWrite(V2, millis() / 1000);  // Send UpTime seconds to App

Should be used for a VitualLabel , you can use V3 or up

1 Like

@waleedtaqi7 You can also look at how I did this here…

1 Like