{"id":13802308,"url":"https://github.com/jacklinquan/micropython-aiobutton","last_synced_at":"2025-03-05T07:34:24.592Z","repository":{"id":57441468,"uuid":"296528424","full_name":"jacklinquan/micropython-aiobutton","owner":"jacklinquan","description":"A MicroPython module for asyncio button.","archived":false,"fork":false,"pushed_at":"2020-09-18T06:02:52.000Z","size":4,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T19:48:35.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacklinquan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-18T06:02:45.000Z","updated_at":"2023-01-14T17:11:07.000Z","dependencies_parsed_at":"2022-09-06T02:40:15.959Z","dependency_job_id":null,"html_url":"https://github.com/jacklinquan/micropython-aiobutton","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-aiobutton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-aiobutton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-aiobutton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-aiobutton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacklinquan","download_url":"https://codeload.github.com/jacklinquan/micropython-aiobutton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241989517,"owners_count":20053798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:41.722Z","updated_at":"2025-03-05T07:34:24.547Z","avatar_url":"https://github.com/jacklinquan.png","language":"Python","readme":"# micropython-aiobutton\n[![PyPI version](https://badge.fury.io/py/micropython-aiobutton.svg)](https://badge.fury.io/py/micropython-aiobutton) [![Downloads](https://pepy.tech/badge/micropython-aiobutton)](https://pepy.tech/project/micropython-aiobutton)\n\nA MicroPython module for asyncio button.\n\nThis module only works under MicroPython and it is tested with MicroPython V1.13.\n\nThis module depends on uasyncio which is a standard package since MicroPython V1.13. It supports all kinds of buttons including buttons sharing a single ADC.\n\nPlease consider [![Paypal Donate](https://github.com/jacklinquan/images/blob/master/paypal_donate_button_200x80.png)](https://www.paypal.me/jacklinquan) to support me.\n\n## Installation\n``` Python\n\u003e\u003e\u003e import upip\n\u003e\u003e\u003e upip.install('micropython-aiobutton')\n```\nAlternatively just copy aiobutton.py to the MicroPython device.\n\n## Usage\n``` Python\nfrom machine import Pin, ADC\nimport uasyncio as aio\nfrom aiobutton import AIOButton\n\n# Button UP and DOWN share a single ADC on pin 32.\nadc_up_down = ADC(Pin(32))\nadc_up_down.atten(ADC.ATTN_11DB)\nadc_up_down.width(ADC.WIDTH_10BIT)\nMAX_ADC = 1023\n\n# Button ENTER is on pin 33 with pull-up enabled.\npin_enter = Pin(33, Pin.IN, Pin.PULL_UP)\n\n# Initialise the button with a handler that takes one argument (the button itself).\n# This handler should return True when the button is pressed, or False otherwise.\n# Default button check time is 10ms, debounce time 50ms and hold time 1000ms.\nbtn_up = AIOButton(\n    lambda btn: (MAX_ADC // 3) \u003c adc_up_down.read() \u003c= (MAX_ADC // 3 * 2)\n)\n# Press handler is triggered when the button is pressed down.\nbtn_up.set_press_handler(\n    lambda btn: print(\"UP is pressed! State:{}\".format(btn.get_debounced()))\n)\n\nbtn_down = AIOButton(lambda btn: (MAX_ADC // 3 * 2) \u003c adc_up_down.read())\n# Release handler is triggered when the button is released.\nbtn_down.set_release_handler(\n    lambda btn: print(\"DOWN is released! State:{}\".format(btn.get_debounced()))\n)\n\nbtn_enter = AIOButton(lambda btn: not pin_enter.value())\n# Hold handler is triggered when the button is held for certain time (default 1000ms).\nbtn_enter.set_hold_handler(\n    lambda btn: print(\"ENTER is held! State:{}\".format(btn.get_debounced()))\n)\n\n\nasync def main():\n    task_up = aio.create_task(btn_up.coro_check())\n    task_down = aio.create_task(btn_down.coro_check())\n    task_enter = aio.create_task(btn_enter.coro_check())\n    while True:\n        await aio.sleep_ms(1)\n\n\naio.run(main())\n```","funding_links":["https://www.paypal.me/jacklinquan"],"categories":["Libraries"],"sub_categories":["IO"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklinquan%2Fmicropython-aiobutton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacklinquan%2Fmicropython-aiobutton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklinquan%2Fmicropython-aiobutton/lists"}