Requesting the state of a PB widget from code on the controller

i could not find a work around for this problem so what i have opted, in consolation, to force the user to continously toggle the PB as required until the desired state is selected. I achieved this by setting a variable when a change in state of the PB is detected by the hardware in such a manner that before the hardware is put into sleep mode it updates the variable according to the state of the PB and then restores that same state to the PB after the hardware returns from sleep. Basically I forced the PB to remain in the state it was in before the hardware goes to sleep, therefore the PB will only change state on the app when the hardware receives the change in state. The code is simple and looks like this:

//Simple code to restore the state of the PB widget after the hardware returns from sleep

  if(PowerSaveMode==1)

        System.sleep(WakeUpPin,RISING,1); 
        //After the program returns from sleep it continues running from here

        if(PBState==0){
        
            Blynk.virtualWrite(V14,0);   
        
        }
        else if(PBState==1){
            
            Blynk.virtualWrite(V14,1);
            
        }
        
        
    }
1 Like