Closed gladyscatface closed 5 months ago
For a callback-free solution see ESwitch. If you want to toggle a Pin
each time a switch closes, adapt the sample code as follows:
async def closure(pin):
while True:
es.close.clear()
await es.close.wait()
pin.value(not pin.value())
Closed due to inactivity.
Thank you Sir, for your help in getting some asyncio code working, is there such a thing as :(sw.toggle_func)?
async def my_app(): pin = Pin(16, Pin.IN, Pin.PULL_UP) # Hardware: switch to gnd red = led sw = Switch(pin) sw.close_func(pulse, (red, 1000)) # Note how coro and args are passed sw.open_func(pulse, (red, 1000)) await asyncio.sleep(60) # Dummy application code
This was cut and pasted from your tutorial, I don't like callbacks, and wish to build mqtt switches without loops that hide away in dark places. Thanks Brian