{"id":16148904,"url":"https://github.com/erriez/erriezrotaryencoderhalfstep","last_synced_at":"2025-04-23T23:15:15.215Z","repository":{"id":52575243,"uuid":"121113642","full_name":"Erriez/ErriezRotaryEncoderHalfStep","owner":"Erriez","description":"3 speed half step Rotary Encoder library for Arduino. Polling and interrupts are supported.","archived":false,"fork":false,"pushed_at":"2021-04-25T10:38:27.000Z","size":1211,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T23:15:08.367Z","etag":null,"topics":["3-speed","arduino","c-plus-plus","documentation","encoder","esp32","esp8266","getting","library","rotary","started","uno"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Erriez.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":"2018-02-11T10:49:03.000Z","updated_at":"2025-01-26T21:49:00.000Z","dependencies_parsed_at":"2022-08-29T01:00:40.224Z","dependency_job_id":null,"html_url":"https://github.com/Erriez/ErriezRotaryEncoderHalfStep","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezRotaryEncoderHalfStep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezRotaryEncoderHalfStep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezRotaryEncoderHalfStep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezRotaryEncoderHalfStep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Erriez","download_url":"https://codeload.github.com/Erriez/ErriezRotaryEncoderHalfStep/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528899,"owners_count":21445518,"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":["3-speed","arduino","c-plus-plus","documentation","encoder","esp32","esp8266","getting","library","rotary","started","uno"],"created_at":"2024-10-10T00:35:13.638Z","updated_at":"2025-04-23T23:15:15.198Z","avatar_url":"https://github.com/Erriez.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 3 speed Rotary Encoder Half Step library for Arduino\n[![Build Status](https://travis-ci.org/Erriez/ErriezRotaryEncoderHalfStep.svg?branch=master)](https://travis-ci.org/Erriez/ErriezRotaryEncoderHalfStep)\n\nThis is an optimized three speed Rotary Encoder library for Arduino which supports:\n\n* Half step Rotary Encoder types.\n* Detect three rotation speeds.\n* Configurable rotation speed sensitivity.\n* Polling and interrupt based.\n* Single or multiple Rotary Encoders.\n* Optional Rotary button.\n* Pin state table in flash.\n\n![Rotary encoder](https://raw.githubusercontent.com/Erriez/ErriezRotaryEncoderHalfStep/master/extras/RotaryEncoder.png)\n\n\n## Half step / half step Rotary Encoders\n\nThe difference between a half step or half step Rotary Encoder type is how the data signals of the two pins are generated. It depends on the mechanical construction of the notches and contacts inside the Rotary Encoder.\n\nPlease refer to the [ErriezRotaryEncoderFullStep](https://github.com/Erriez/ErriezRotaryEncoderFullStep) library for full step Rotary Encoders. \nExperiment with the full step and half step libraries which works optimal for your Rotary Encoder.\n\n\n## Hardware\n\nConnect the two rotary pins to the DIGITAL pins of an Arduino board.\n\nA third rotary button pin is not used in the Rotary library, but can be used in the sketch.\n\nTested with Arduino IDE v1.8.13 on hardware:\n\n* Arduino UNO\n* Arduino Nano\n* Arduino Micro\n* Arduino Pro or Pro Mini\n* Arduino Mega or Mega2560\n* Arduino Leonardo\n* WeMos D1 R2 \u0026 mini (ESP8266)\n\nOther supported targets:\n* ESP8266\n* ESP32\n* SAMD21\n* STM32F1\n\n### Interrupts\n\nBoth rotary pins must be connected to a DIGITAL pin with interrupt support, such as `INT0` or `INT1`. This is chip specific. Please refer to the documentation of your board or [attachInterrupt()](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/).\n\n\n### Arduino UNO hardware\n\nThe connection below can be used for polled and interrupts. An optional button pin can be connected to DIGITAL pin 4.\n\n![3-pin Rotary Encoder Arduino connection](https://raw.githubusercontent.com/Erriez/ErriezRotaryEncoderHalfStep/master/extras/FritzingRotary.png)\n\n|    Rotary pin     | Arduino UNO/NANO/Mega2560/Leonardo board |\n| :---------------: | :--------------------------------------: |\n|         1         |           DIGITAL pin 2 (INT0)           |\n|         2         |           DIGITAL pin 3 (INT1)           |\n| Button (optional) |              DIGITAL pin 4               |\n|        GND        |                   GND                    |\n\n\n### Arduino WeMos D1 R2 \u0026 mini (ESP8266) hardware\n\nNote that some ESP8266 pins mixes ESP8622 GPIO pins with Arduino digital pins. Connect a Rotary Encoder to the following pins which can be used with polled and interrupt examples:\n\n|    Rotary pin     | ESP8622 pin | Text on board / WeMos D1 \u0026 R2 |\n| :---------------: | :---------: | :---------------------------: |\n|         1         |   GPIO13    |           D7 (MOSI)           |\n|         2         |   GPIO12    |           D6 (MISO)           |\n| Button (optional) |   GPIO14    |           D5 (SCK)            |\n|  LED (Not used)   |    GPIO2    |               D4               |\n|        GND        |     GND     |              GND               |\n\n**Note:** An external pull-up resistor is required when a pin does not have an internal pull-up.\n\n```c++\n// Connect the rotary pins to the WeMos D1 R2 board:\n#define ROTARY_PIN1         12\n#define ROTARY_PIN2         13\n#define ROTARY_BUTTON_PIN   14\n```\n\n\n## Examples\n\nThe following examples are available:\n* Rotary | Interrupt | [InterruptHalfStepBasic](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Interrupt/InterruptHalfStepBasic/InterruptHalfStepBasic.ino)\n* Rotary | Interrupt | [InterruptHalfStepButton](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Interrupt/InterruptHalfStepButton/InterruptHalfStepButton.ino)\n* Rotary | Interrupt | [InterruptHalfStepCounter](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Interrupt/InterruptHalfStepCounter/InterruptHalfStepCounter.ino)\n* Rotary | Polled | [PolledHalfStepBasic](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Polled/PolledHalfStepBasic/PolledHalfStepBasic.ino)\n* Rotary | Polled | [PolledHalfStepButton](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Polled/PolledHalfStepButton/PolledHalfStepButton.ino)\n* Rotary | Polled | [PolledHalfStepCounter](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Polled/PolledHalfStepCounter/PolledHalfStepCounter.ino)\n* Rotary | Polled | [PolledHalfStepMultiple](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/blob/master/examples/Polled/PolledHalfStepMultiple/PolledHalfStepMultiple.ino)\n\n\n## Documentation\n\n- [Doxygen online HTML](https://Erriez.github.io/ErriezRotaryEncoderHalfStep)\n- [Doxygen PDF](https://github.com/Erriez/ErriezRotaryEncoderHalfStep/raw/master/ErriezRotaryEncoderHalfStep.pdf)\n\n\n## Usage\n\n**Read rotary with polling**\n```c++\n#include \u003cErriezRotaryHalfStep.h\u003e\n\n\n// Connect rotary pins to the DIGITAL pins of the Arduino board\n#define ROTARY_PIN1   2\n#define ROTARY_PIN2   3\n  \n// Enable ONE of the three constructors below with different number of arguments:\n\n// Initialize half step rotary encoder, default pull-up enabled, default \n// sensitive=100\nRotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2);\n\n// Or initialize half step rotary encoder, pull-up disabled, default sensitive=100\n// RotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2, false);\n\n// Or initialize half step rotary encoder, pull-up enabled, sensitive 1..255\n// A higher value is more sensitive\n// RotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2, true, 150);\n\nvoid loop()\n{\n  int rotaryState = rotary.read();\n  \n  // rotaryState = -3: Counter clockwise turn, multiple notches fast\n  // rotaryState = -2: Counter clockwise turn, multiple notches\n  // rotaryState = -1: Counter clockwise turn, single notch\n  // rotaryState = 0:  No change\n  // rotaryState = 1:  Clockwise turn, single notch\n  // rotaryState = 2:  Clockwise turn, multiple notches\n  // rotaryState = 3:  Clockwise turn, multiple notches fast\n}\n```\n\n**Read rotary with interrupts**\n\n```c++\n#include \u003cErriezRotaryHalfStep.h\u003e\n\n// Connect rotary pins to Arduino DIGITAL pins with interrupt support:\n//\n// +-----------------------------------+--------------------------+\n// |              Board                |  DIGITAL interrupt pins  |\n// +-----------------------------------+--------------------------+\n// | Uno, Nano, Mini, other 328-based  |  2, 3                    |\n// | Mega, Mega2560, MegaADK           |  2, 3, 18, 19, 20, 21    |\n// | Micro, Leonardo, other 32u4-based |  0, 1, 2, 3, 7           |\n// +-----------------------------------+--------------------------+\n//\n#define ROTARY_PIN1   2\n#define ROTARY_PIN2   3\n\n// Enable ONE of the three constructors below with different number of arguments:\n\n// Initialize half step rotary encoder, default pull-up enabled, default \n// sensitive=100\nRotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2);\n\n// Or initialize half step rotary encoder, pull-up disabled, default sensitive=100\n// RotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2, false);\n\n// Or initialize half step rotary encoder, pull-up enabled, sensitive 1..255\n// A higher value is more sensitive\n// RotaryHalfStep rotary(ROTARY_PIN1, ROTARY_PIN2, true, 150);\n\nvoid setup()\n{\n  // Initialize pin change interrupt on both rotary encoder pins\n  attachInterrupt(digitalPinToInterrupt(ROTARY_PIN1), rotaryInterrupt, CHANGE);\n  attachInterrupt(digitalPinToInterrupt(ROTARY_PIN2), rotaryInterrupt, CHANGE);\n}\n\nvoid rotaryInterrupt()\n{\n  int rotaryState = rotary.read();\n  \n  // rotaryState = -3: Counter clockwise turn, multiple notches fast\n  // rotaryState = -2: Counter clockwise turn, multiple notches\n  // rotaryState = -1: Counter clockwise turn, single notch\n  // rotaryState = 0:  No change\n  // rotaryState = 1:  Clockwise turn, single notch\n  // rotaryState = 2:  Clockwise turn, multiple notches\n  // rotaryState = 3:  Clockwise turn, multiple notches fast\n}\n```\n\n\n## Library dependencies\n\n- None.\n\n\n## Library installation\n\nPlease refer to the [Wiki](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches/wiki) page.\n\n\n## Other Arduino Libraries and Sketches from Erriez\n\n* [Erriez Libraries and Sketches](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferriez%2Ferriezrotaryencoderhalfstep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferriez%2Ferriezrotaryencoderhalfstep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferriez%2Ferriezrotaryencoderhalfstep/lists"}