(FIXED)Synchronizing styled button state with the state of digital pin

Good day everyone, I’m doing a project where in an extension socket can be turn on and off using the blynk app and would also turn off when the temperature exceed 35C. Currently the “Styled button” in the blynk app is hooked directly with D11 (this is where my relay signal is connected too). My problem is when the temperature exceeds 35C and thus turning off D11 with DigitalWrite(11, LOW) the “Styled button” state remains in an “ON” state. I want the styled button state to be also “OFF” when pin D11 is turned off. Bare with me its my first time using arduino and blynk :slight_smile: Should i first link the Styled button to a virtual pin? then connect it to a digital pin?

any help would be appreciated thank you :slight_smile:

EDIT: ( FIXED)
for anyone who will stumble upon this too haha i’ve fixed it using

BLYNK_WRITE(0) // At global scope (not inside of the function)
{
    int i = param.asInt();
    if (i == 1) 
    {
        digitalWrite(11, HIGH);
    }
    else 
    {
        digitalWrite(11, LOW);
    }
}

Yes, then you can have full control and feedback.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/what-is-virtual-pins

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-control-anything-with-blynk-app

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-display-any-sensor-data-in-blynk-app

1 Like

PS, I didn’t see your edit as it was in the unformatted code… and I refuse to read unformatted code :stuck_out_tongue:

But I was feeling generous and formatted it for you, only then to see the edit… so looks like you have a handle on the Virtual Pin thing after all :smiley:

PPS your variable i is NOT globally defined and thus that value is only usable inside that function… in case you ever wanted to reference it or not.

1 Like

thank you very much. i’ll be sure to follow the rules next time.