I’ve two virtual buttons, btn0 and btn1. I want to change the properties of btn1 when I’m pressing btn0 and when releasing it, bringing the original settings back to btn1.
The following code is not working and cannot find the reason.
Any help is appreciated.
TIA
btn0status = '0'
@blynk.VIRTUAL_WRITE('0')
def btn0_handler(value):
global btn0status
btn0status = value[0]
if btn0status == '1':
print('Btn pressed')
blynk.set_property('1', 'offColor', '#FFFFFF')
blynk.set_property('1', 'offBackColor', '#000000')
blynk.set_property('1',' offLabel', 'READY')
else:
print('Btn released')
blynk.set_property('1', 'onColor', '#000000')
blynk.set_property('1', 'onBackColor', '#FFFFFF')
blynk.set_property('1', 'onLabel', 'NOT READY')
@blynk.VIRTUAL_WRITE(1)
def btn1_handler(value):
#security check
#btn1 is activated only when btn0 is being pressed
if value[0] == '1' and btn0status == '1':
print('2n btn pressed')
These don’t look like vPins… in fact you have ’ ’ around all sorts of numbers in your code??? I thought it might be because you posted it unformatted (normally a no0B mistake ) but nope, I fixed the formatting and that is the way you posted it.
I didn’t claim to understand the whys… I just had to change all my code around once in order to make it work, once I updated the library. It has been awhile since I played around with it so may even need further updating.
EDIT - well, I can finally revert my code back to “normal”… don’t know how or why, but it took me a lot of trial and error to come up with the “solution” awhile back. But doesn’t seem needed now.
Anyhow, @Emilio since I had not used set_property() in any of my Python coding yet, I tested your code as well… I don’t know your exact expected results, but think you are mixing up your onColor, onBackColor, offColor, offBackColor commands. I juggled them around a bit (AKA set them all to off) and everything is changing as expected.
On stand-by, btn1 should display ‘NOT READY’. When btn0 is pressed, btn1 should change to ‘READY’. When released, the text for btn1 should go back to ‘NOT READY’