Arduino/ESP 库,用于简化旋转编码器数据的读取。
Arduino/ESP library to simplify reading rotary encoder data.
This library allows you read out interactions with a rotary encoder and act on them. It uses callback functions to be notified when the rotary encoder changes.
It has been tested with Arduino, ESP8266 and ESP32 devices.
To see the latest changes to the library please take a look at the Changelog.
If you find this library helpful please consider giving it a ⭐️ at GitHub and/or buy me a ☕️. Thanks!
Some of the code based of this library is based on code from PJRC.
begin() or the parameterized constructor to create a new instance of the classvoid setStepsPerClick(int steps)int getStepsPerClick() constvoid setChangedHandler(CallbackFunction f)void setRightRotationHandler(CallbackFunction f)void setLeftRotationHandler(CallbackFunction f)void setUpperOverflowHandler(CallbackFunction f)void setLowerOverflowHandler(CallbackFunction f)void setUpperBound(int upper_bound)void setLowerBound(int lower_bound)int getUpperBound() constint getLowerBound() constretriggerEvent(false)void triggerOnBounds(false)int getPosition() constbyte getDirection() constString directionToString(byte direction) constvoid setIncrement(int inc)int getIncrement() constvoid setSpeedupInterval(int time)void setSpeedupIncrement(int inc)75ms and the increment is set to 5.int getSpeedupInterval() constint getSpeedupIncrement() constvoid enableSpeedup(bool enable)bool isSpeedupEnabled() constvoid setSpeedupStartedHandler(CallbackFunction f)void setSpeedupEndedHandler(CallbackFunction f)bool isInSpeedup() constloop() member function in your sketch's loop() function.loop()function.getID().setID(int newID) to set a new one. But then you need to make sure that they are unique.== operator to compare encodersvoid setContext(void* ctx) stores a void* on the encoder instance.void* getContext() const returns it.ESPRotary& and cast it back:class Dial {
public:
void begin(byte p1, byte p2) {
r.begin(p1, p2, 4);
r.setContext(this); // hand the encoder a pointer back to us
r.setChangedHandler(Dial::onRotate);
}
void loop() { r.loop(); }
static void onRotate(ESPRotary& sender) {
Dial* self = static_cast(sender.getContext());
self->handle(sender.getPosition());
}
private:
void handle(int pos) { /* ... */ }
ESPRotary r;
};These are the constructor and the member functions the library provides:
…Open the Arduino IDE choose "Sketch > Include Library" and search for "ESP Rotary". Or download the ZIP archive (), and choose "Sketch > Include Library > Add .ZIP Library..." and select the downloaded file.
MIT License
Copyright (c) 2017-2026 Lennart Hennigs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
暂无开放 Issues,或尚未同步最近议题。