{"id":14437145,"url":"https://github.com/sparkfun/pxt-gamer-bit","last_synced_at":"2025-08-23T19:44:34.509Z","repository":{"id":21655804,"uuid":"94376134","full_name":"sparkfun/pxt-gamer-bit","owner":"sparkfun","description":"SparkFun gamer:bit package for Microsoft MakeCode - beta","archived":false,"fork":false,"pushed_at":"2024-04-03T14:06:46.000Z","size":80,"stargazers_count":4,"open_issues_count":4,"forks_count":13,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-05-29T00:45:31.913Z","etag":null,"topics":["microbit","pxt","sparkfun"],"latest_commit_sha":null,"homepage":"https://makecode.microbit.org/pkg/sparkfun/pxt-gamer-bit","language":"TypeScript","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/sparkfun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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,"zenodo":null}},"created_at":"2017-06-14T21:55:04.000Z","updated_at":"2022-11-16T13:34:10.000Z","dependencies_parsed_at":"2025-04-14T21:32:01.045Z","dependency_job_id":null,"html_url":"https://github.com/sparkfun/pxt-gamer-bit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/sparkfun/pxt-gamer-bit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkfun%2Fpxt-gamer-bit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkfun%2Fpxt-gamer-bit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkfun%2Fpxt-gamer-bit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkfun%2Fpxt-gamer-bit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sparkfun","download_url":"https://codeload.github.com/sparkfun/pxt-gamer-bit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkfun%2Fpxt-gamer-bit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271767275,"owners_count":24817579,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["microbit","pxt","sparkfun"],"created_at":"2024-08-31T08:00:24.221Z","updated_at":"2025-08-23T19:44:34.451Z","avatar_url":"https://github.com/sparkfun.png","language":"TypeScript","funding_links":[],"categories":["编程"],"sub_categories":["JavaScript 和 MakeCode"],"readme":"# gamer:bit\n\n![SparkFun Gamer:bit](https://raw.githubusercontent.com/sparkfun/pxt-gamer-bit/master/icon.png)  \n\nThe package adds support for the controller:bit and **gamer:bit** add-on board from SparkFun.\n\nTo use this package, go to https://makecode.microbit.org, click ``Add package`` and search for **gamerbit**.\n\n### ~ hint\n\nThis package is still under development and subject to changes.\n\n### ~\n\n## Usage\n\n* Button pins are named to function.\n* Provides button state detection block.\n* Runs user code on button changed events.\n* Configures pins to pull-up.\n\n### Pin names\n\nThe micro:bit pins are named to match gamepad functions:\n\n* ``P0`` -- D-PAD up\n* ``P1`` -- D-PAD left\n* ``P2`` -- D-PAD right\n* ``P8`` -- D-PAD down\n* ``P12`` -- Y button (right-hand, left button)\n* ``P16`` -- X button (right-hand, right button)\n* ``P5`` -- A button (micro:bit, left button)\n* ``P11`` -- B button (micro:bit, right button)\n\nThe button pins are automatically configured as pull-up when using the package.\n\n### Reading button states\n\nUse the logical plug-in blocks to read if the button is pressed.\n\n```blocks\nif (gamerbit.isPressed(GamerBitPin.P0)) {\n    led.plot(0, 0)\n} else {\n    led.unplot(0, 0)\n}\n```\n\n*Example turns on LED when button is pressed*\n\n### Button events\n\nCustom code can be run when a button event happens.\n\nThey can be triggered on:\n\n* down (pressed)\n* up (released)\n* clicked (pressed then released)\n\n```blocks\ngamerbit.onEvent(GamerBitPin.P0, GamerBitEvent.Down, () =\u003e {\n    led.plot(0, 0)\n})\ngamerbit.onEvent(GamerBitPin.P0, GamerBitEvent.Up, () =\u003e {\n    led.unplot(0, 0)\n})\n```\n\n*Example turns on LED when button is pressed*\n\n## Examples\n\n### Example: Remote controlled a microservo\n\nThis program uses the left, right, up buttons\nand sends the servo angle over radio.\n\n```blocks\n// gamer:bit code\ngamerbit.onEvent(GamerBitPin.P0, GamerBitEvent.Down, () =\u003e {\n    // go straight\n    radio.sendNumber(90)\n});\ngamerbit.onEvent(GamerBitPin.P1, GamerBitEvent.Down, () =\u003e {\n    // turn left\n    radio.sendNumber(45)\n});\ngamerbit.onEvent(GamerBitPin.P2, GamerBitEvent.Down, () =\u003e {\n    // turn right\n    radio.sendNumber(135)\n});\n\n// robot code\nradio.onDataPacketReceived( ({ receivedNumber }) =\u003e  {\n    pins.servoWritePin(AnalogPin.P0, receivedNumber)\n})\n```\n\n### Example: Sending a packet of data over wireless\n\nThe following program creates a bit field from the state of the buttons on the gamer:bit and sends it with the radio.  This is meant to be decoded with the moto:bit example to make a simple RC robot.\n\n\n```blocks\nlet packet = 0\nbasic.forever(() =\u003e {\n    packet = 0\n    if (gamerbit.isPressed(GamerBitPin.P0)) {\n        led.plot(1, 0)\n        packet = packet + 128\n    } else {\n        led.unplot(1, 0)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P1)) {\n        led.plot(0, 1)\n        packet = packet + 64\n    } else {\n        led.unplot(0, 1)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P2)) {\n        led.plot(2, 1)\n        packet = packet + 32\n    } else {\n        led.unplot(2, 1)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P8)) {\n        led.plot(1, 2)\n        packet = packet + 16\n    } else {\n        led.unplot(1, 2)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P12)) {\n        led.plot(3, 2)\n        packet = packet + 8\n    } else {\n        led.unplot(3, 2)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P16)) {\n        led.plot(4, 2)\n        packet = packet + 4\n    } else {\n        led.unplot(4, 2)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P5)) {\n        led.plot(3, 0)\n        packet = packet + 2\n    } else {\n        led.unplot(3, 0)\n    }\n    if (gamerbit.isPressed(GamerBitPin.P11)) {\n        led.plot(4, 0)\n        packet = packet + 1\n    } else {\n        led.unplot(4, 0)\n    }\n    radio.sendNumber(packet)\n})\nradio.setGroup(13)\n```\n\n## License\n\nMIT\n\n## Supported targets\n\n* for PXT/microbit\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkfun%2Fpxt-gamer-bit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsparkfun%2Fpxt-gamer-bit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkfun%2Fpxt-gamer-bit/lists"}