I have started to learn MicroPython recently, there is one problem I struggled for a while, I have been searching for solutions online and still have no clew what to do. Please help, Thanks.
This is the code, I have used aswitch.py module, I wish to achieve when I am double click the button, only the Yellow LED lights up( the Blue LED has no reaction while there is a double click of the button). and When this is long press, only the Green LED lights up. ( the Blue LED has no reaction while there is a long press of the button)
How should I change the Code to reach this function?
Code: Select all
from pyb import LED from machine import Pin import uasyncio as asyncio from aswitch import Pushbutton def toggle(led): led.toggle() async def my_app(): await asyncio.sleep(600) pin = Pin('X1', Pin.IN, Pin.PULL_UP) # Pushbutton to gnd blue = LED(4) yellow = LED(3) green = LED(2) pb = Pushbutton(pin) pb.press_func(toggle, (blue,)) # Note how function and args are passed pb.double_func(toggle, (yellow,)) # Note how function and args are passed pb.long_func(toggle, (green,)) # Note how function and args are passed loop = asyncio.get_event_loop() loop.run_until_complete(my_app()) # Run main application code