Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question? #117

Closed
gladyscatface opened this issue Mar 26, 2024 · 2 comments
Closed

question? #117

gladyscatface opened this issue Mar 26, 2024 · 2 comments

Comments

@gladyscatface
Copy link

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

@peterhinch
Copy link
Owner

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())

@peterhinch
Copy link
Owner

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants