{"id":16977403,"url":"https://github.com/mryslab/gamerbit","last_synced_at":"2026-04-17T19:04:24.484Z","repository":{"id":72328482,"uuid":"118348364","full_name":"MrYsLab/gamerbit","owner":"MrYsLab","description":"A class to monitor the Sparkfun gamer:bit board","archived":false,"fork":false,"pushed_at":"2018-01-21T16:10:13.000Z","size":324,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-18T12:58:10.407Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrYsLab.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T15:43:15.000Z","updated_at":"2020-08-07T22:36:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0687736-e671-405b-a585-0606f9bcfe7d","html_url":"https://github.com/MrYsLab/gamerbit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MrYsLab/gamerbit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrYsLab%2Fgamerbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrYsLab%2Fgamerbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrYsLab%2Fgamerbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrYsLab%2Fgamerbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrYsLab","download_url":"https://codeload.github.com/MrYsLab/gamerbit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrYsLab%2Fgamerbit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31941845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-14T01:28:52.916Z","updated_at":"2026-04-17T19:04:24.465Z","avatar_url":"https://github.com/MrYsLab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A micro:bit MicroPython Class To Control The  [SparkFun gamer:bit Board](https://www.sparkfun.com/products/14215)\n![logo](https://raw.github.com/MrYsLab/gamerbit/master/images/gamer_bit.png)\n\n\nThe GamerBit class, [gamer_bit.py](https://github.com/MrYsLab/gamerbit/blob/master/gamer_bit.py), \nprovides an easy to use Python interface for the SparkFun gamer:bit board.\nIt maintains its own self-starting event loop that monitors \nstate changes for all of the gamer:bit buttons, including the *Poke home connectors* \nused for external inputs. \n\nWhen the event loop detects a state change, it forms a report and sends this report\nto a callback function that was specified when GamerBit was instantiated.\n\n# gamer_bit.py\n```\n# GamerBit API:\nclass GamerBit:\n    \"\"\"\n    This class supports the Sparkfun gamer:bit board.\n    When instantiating, you must specify a callback function\n    that will receive a state change report when a button is pressed\n    or released.\n\n    A callback report is a Python dictionary that contains elements for all pins\n    that have changed state. The keys for this report are:\n    'pin0', 'pin1', 'pin2', 'pin8', 'pin12', 'pin16', 'button_a', 'button_b'\n    \n    For example, if the P0 button is pressed, the report you should expect\n    to see is:\n    \n    {'pin0': 1}\n    \n    The value for the entry specifies the state, 1 = pressed or on and 0 = released or off.\n\n    Reports are only generated when there is a state change, allowing you to\n    craft event driven applications.\n    \n    Be cautious in crafting your callback function, since it is a blocking\n    call. Keep it as short as possible.\n\n    If you wish to receive notification of multiple buttons being pressed\n    simultaneously, increase the \"scans\" parameter to a value where multiple\n    button presses are being reported. For example, to get notification of\n    2 buttons being pressed simultaneously, set scans to 4.\n    \n    \"\"\"\n    def __init__(self, callback, scans=1):\n        \"\"\"\n        \n        Set the callback function and number of scans\n        per polling cycle\n        :param callback: external callback function\n        :param scans: Number of scans to perform before report is generated\n        \"\"\"\n        \n        \n# Usage Example:\ndef my_gamer_bit_callback_handler(report):\n   # examine the report and act upon it to support your\n   # application\n   \n# instantiate the GamerBit class\n\ngb = GamerBit(my_gamer_bit_callback_handler)\n\n```\n\n## Using the class\n[This article](https://microbit-playground.co.uk/howto/add-python-module-microbit-micropython) explains how to add\na third party library, like k_motor.py, to the micro:bit persistent file system.\n\nAlthough more \"pythonic\" than simply adding the GamerBit class to the top of of the application, as was done for the [included\nexample](https://github.com/MrYsLab/gamerbit/blob/master/examples/example.py), this method has some drawbacks. If you\nmake any changes to the application, the entire procedure of loading of the application and library has to be repeated.\n\nTherefore, adding the GamerBit class to the top of the application during development is more convenient. Once the application is\ndebugged and complete, using the persistent file system method is totally appropriate.\n\nTo help save value memory space in the micro:bit, a minimized file, \n[gamer_bit_minimized.py](https://github.com/MrYsLab/gamerbit/blob/master/gamer_bit_minimized.py)\n has been provided for your convenience. It removes all comments and \nunnecessary while space from gamerbit.py.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmryslab%2Fgamerbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmryslab%2Fgamerbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmryslab%2Fgamerbit/lists"}