{"id":16525530,"url":"https://github.com/andrewn/raspi-rotary-encoder","last_synced_at":"2025-09-21T23:32:51.228Z","repository":{"id":66464820,"uuid":"68235059","full_name":"andrewn/raspi-rotary-encoder","owner":"andrewn","description":"Add Rotary Encoders to your Raspberry Pi with ease","archived":false,"fork":false,"pushed_at":"2017-09-16T08:56:43.000Z","size":22,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T05:54:12.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/andrewn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-09-14T19:09:58.000Z","updated_at":"2022-04-10T15:35:45.000Z","dependencies_parsed_at":"2023-05-29T03:30:25.086Z","dependency_job_id":null,"html_url":"https://github.com/andrewn/raspi-rotary-encoder","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"7f1ca4f311dbdb62309121823ea1c9a608c93bb7"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewn%2Fraspi-rotary-encoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewn%2Fraspi-rotary-encoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewn%2Fraspi-rotary-encoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewn%2Fraspi-rotary-encoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewn","download_url":"https://codeload.github.com/andrewn/raspi-rotary-encoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233808835,"owners_count":18733598,"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-10-11T17:03:51.310Z","updated_at":"2025-09-21T23:32:45.940Z","avatar_url":"https://github.com/andrewn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Raspi Rotary Encoder\n==========\n\nAdd Rotary Encoders to your Raspberry Pi with ease!\n\nRotary Encoder is inspired by, and designed to work with [@nebrius'](https://github.com/nebrius) [Raspi.js suite](https://github.com/nebrius/raspi). This README is heavily based on those tools.\n\nIf you have a bug report, feature request, or wish to contribute code, please be sure to check out the [Contributing Guide](blob/master/CONTRIBUTING.md).\n\n## Installation\n\nInstall [raspi](https://github.com/nebrius/raspi) as this library uses that to set-up the Pi and configure the GPIO pins.\n\nInstall `raspi-rotary-encoder` with NPM:\n\n```Shell\nnpm install raspi-rotary-encoder\n```\n\n**Warning**: this module's dependencies require GCC 4.8 or newer. This means that you should be running Raspbian Jessie or newer, released in September of 2015.\n\n\n## Example Usage\n\n```JavaScript\nvar raspi = require('raspi');\nvar RotaryEncoder = require('raspi-rotary-encoder').RotaryEncoder;\n\nraspi.init(function() {\n  var encoder = new RotaryEncoder({\n    pins: { a: 5, b: 4 },\n    pullResistors: { a: \"up\", b: \"up\" }\n  });\n\n  encoder.addListener('change', function (evt) {\n    console.log('Count', evt.value);\n  })\n});\n```\n\n## Pin Naming\n\nThe pins on the Raspberry Pi are a little complicated. There are multiple headers on some Raspberry Pis with extra pins, and the pin numbers are not consistent between Raspberry Pi board versions.\n\nTo help make it easier, you can specify pins in three ways. The first is to specify the pin by function, e.g. ```'GPIO18'```. The second way is to specify by pin number, which is specified in the form \"P[header]-[pin]\", e.g. ```'P1-7'```. The final way is specify the [Wiring Pi virtual pin number](http://wiringpi.com/pins/), e.g. ```7```. If you specify a number instead of a string, it is assumed to be a Wiring Pi number.\n\n## API\n\n### new RotaryEncoder(config)\n\nInstantiates a new RotaryEncoder instance using the config object properties:\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eProperty\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epins\u003c/td\u003e\n    \u003ctd\u003eObject\u003c/td\u003e\n    \u003ctd\u003e```{ a, b }```. Object of the pins to use for the encoder's A and B pins. The values for ```a``` and ```b``` can be a number or string as described in \"Pin naming\" above.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003cth\u003eProperty\u003c/th\u003e\n            \u003cth\u003eType\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003ea\u003c/td\u003e\n          \u003ctd\u003eNumber | String\u003c/td\u003e\n          \u003ctd\u003eThe pin number connected to the A leg of the encoder\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n        \u003ctd\u003eb\u003c/td\u003e\n          \u003ctd\u003eNumber | String\u003c/td\u003e\n          \u003ctd\u003eThe pin number connected to the B leg of the encoder\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epullResistors\u003c/td\u003e\n    \u003ctd\u003eObject (optional)\u003c/td\u003e\n    \u003ctd\u003e```{ a, b }```. Object of the pull-up or pull-down resistors to use (if any) for the encoder's A and B pins. \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003cth\u003eProperty\u003c/th\u003e\n            \u003cth\u003eType\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003ea\u003c/td\u003e\n          \u003ctd\u003eString\u003c/td\u003e\n          \u003ctd\u003eThe strings ```up```, ```down``` or ```none``` are valid.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n          \u003ctd\u003eb\u003c/td\u003e\n          \u003ctd\u003eString\u003c/td\u003e\n          \u003ctd\u003eThe strings ```up```, ```down``` or ```none``` are valid.\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Instance Properties\n\nNone\n\n### Instance Methods\n\n#### addListener(eventName, callback)\n\nRegister an event listener function callback\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eeventName\u003c/td\u003e\n    \u003ctd\u003eString\u003c/td\u003e\n    \u003ctd\u003eA valid event name (see Events below)\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ecallback\u003c/td\u003e\n    \u003ctd\u003eFunction\u003c/td\u003e\n    \u003ctd\u003eA function to be called whenever the event occurs\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: A reference to this encoder instance\n\n#### removeListener(eventName, callback)\n\nUnregister an event listener function callback\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eeventName\u003c/td\u003e\n    \u003ctd\u003eString\u003c/td\u003e\n    \u003ctd\u003eA valid event name (see Events below)\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ecallback\u003c/td\u003e\n    \u003ctd\u003eFunction\u003c/td\u003e\n    \u003ctd\u003eA listener function that was previously registered with addListener\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: A reference to this encoder instance\n\n## Events\n\nUse `addListener` to listen for events. Listener callback functions will be passed an event object containing information about the event.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eEvent name\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003echange\u003c/td\u003e\n    \u003ctd\u003eFires when the rotary encoder is turned in either direction. The listener is passed a single object with the following property:\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ctable\u003e\n        \u003cthead\u003e\n          \u003ctr\u003e\n            \u003cth\u003eProperty\u003c/th\u003e\n            \u003cth\u003eType\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n          \u003c/tr\u003e\n        \u003c/thead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003evalue\u003c/td\u003e\n          \u003ctd\u003eNumber\u003c/td\u003e\n          \u003ctd\u003eAn ever-increasing or decreasing number. Positive numbers indicate clockwise, negative indicate anticlockwise. These do not correspond to a full-rotation of the encoder.\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nLicense\n=======\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Andrew Nicolaou \u003cme@andrewnicolaou.co.uk\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewn%2Fraspi-rotary-encoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewn%2Fraspi-rotary-encoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewn%2Fraspi-rotary-encoder/lists"}