{"id":19484399,"url":"https://github.com/funnygeeker/micropython-easybutton","last_synced_at":"2025-06-29T09:03:36.902Z","repository":{"id":113375047,"uuid":"601090477","full_name":"funnygeeker/micropython-easybutton","owner":"funnygeeker","description":"Implements various button state recognition using interrupts. 使用中断实现的多种按钮状态识别，适用于 MicroPython","archived":false,"fork":false,"pushed_at":"2024-01-03T13:17:21.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T11:53:59.231Z","etag":null,"topics":["button","esp32","esp8266","irc","micropython","pin","python","rp2040"],"latest_commit_sha":null,"homepage":"","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/funnygeeker.png","metadata":{"files":{"readme":"README.ZH-CN.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-02-13T10:51:59.000Z","updated_at":"2024-07-22T01:56:20.000Z","dependencies_parsed_at":"2023-12-27T15:57:41.101Z","dependency_job_id":null,"html_url":"https://github.com/funnygeeker/micropython-easybutton","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/funnygeeker/micropython-easybutton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnygeeker%2Fmicropython-easybutton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnygeeker%2Fmicropython-easybutton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnygeeker%2Fmicropython-easybutton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnygeeker%2Fmicropython-easybutton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funnygeeker","download_url":"https://codeload.github.com/funnygeeker/micropython-easybutton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnygeeker%2Fmicropython-easybutton/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262566831,"owners_count":23329681,"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":["button","esp32","esp8266","irc","micropython","pin","python","rp2040"],"created_at":"2024-11-10T20:21:19.484Z","updated_at":"2025-06-29T09:03:36.881Z","avatar_url":"https://github.com/funnygeeker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English (英语)](./README.md)\n# micropython-easybutton\n- 使用中断实现的多种按钮状态识别，按钮按下时执行指定函数，适用于 `micropython`\n\n### 功能\n- 按钮按下后，每隔一段时间执行一次函数\n- 按钮短按后，松开时执行函数\n- 按钮长按后，松开时执行函数\n- 按钮按下时执行函数\n- 按钮松开时执行函数\n\n### 说明\n`./main.py` 为使用示例文件\n`./lib/easybutton.py` 为按钮库文件\n\n### 示例\n- 在本次示例中，按钮所在的引脚接按钮，按钮接的是 `GND`\n\n```python\nimport time\nfrom machine import Pin\nfrom lib.easybutton import EasyButton\n\n# Initialize the button\nbtn = Pin(2, Pin.IN, Pin.PULL_UP)\n# if there are any non-standard naming, please submit a PR, thanks.\n# 如果有不规范的命名，请提交 PR，谢谢\nb = EasyButton(btn)\n\n# Define functions, they can be defined first or later used as anonymous functions\n# 定义函数，可以先定义，也可以后续使用匿名函数\ndef test():\n    print(\"up\")\n\n# Set trigger functions for the button\nb.down_func = lambda: print(\"down\")  # Executed when the button is pressed  # 按钮按下时执行\nb.hold_func = lambda: print(\"hold\")  # Executed at regular intervals after the button is pressed  # 按钮按下后，每隔一段时间执行一次\nb.short_func = lambda: print(\"short\")  # Executed when the button is short pressed and released  # 按钮短按后，松开时执行\nb.long_func = (print, \"long\")  # Executed when the button is long pressed and released  # 按钮长按后，松开时执行\nb.up_func = test  # Executed when the button is released  # 按钮松开时执行函数\n\n# Since an interrupt is used, the code can continue to execute, and it will only pause when the button is pressed.\n# 由于使用了中断，所以后续可以继续执行代码，只有在按钮被按下时才会暂停继续执行的代码，松开则恢复\n# This loop is not necessary, it's just for demonstration purposes. It's not necessary in actual use.\n# 这里的循环并不是必须，仅为演示使用，实际使用中并非必要\nwhile True:\n    print(\"---- running ----\")\n    time.sleep(1)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunnygeeker%2Fmicropython-easybutton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunnygeeker%2Fmicropython-easybutton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunnygeeker%2Fmicropython-easybutton/lists"}