Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sabeechen authored Apr 30, 2018
1 parent d303a57 commit 95cbc9a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
Simple Rotary Encoder
Simple Incremental Rotary Encoder
==========

* Author: Stephen Beechen
* Copyright (C) 2018 Stephen Beechen.
* Released under the MIT license.

Arduino library for reading a rotary encoder with a button on an ESP8266.
Arduino IDE library for reading an incremental rotary encoder, with a push button, with or without using interrupts, on an ESP8266, Arduino, or other Arduino IDE compatible board.


Description
-----------

Callbacks are used to handle events; one each for button up, button down, clockwise rotation and counter clockwise rotation.
Supports reading information from [Incremental Rotary Encoders](https://en.wikipedia.org/wiki/Rotary_encoder#Incremental_rotary_encoder), for example https://www.adafruit.com/product/377 or http://a.co/0OrQ2Hm. Callbacks are used to handle events; one each for button up, button down, clockwise rotation and counter clockwise rotation.

How to Use
----------

The library provides the following methods:

```
RotaryEncoder(int rotaryPin1, int rotaryPin2, int buttonPin)
void setup();
void setButtonDownCallback(Callback cb);
void setup(); // must be called
void setupInterrupts(); //must be called if using interrupts
void loop(); // Must be called in sketch loop() if you aren't using interrupts
void setButtonDownCallback(Callback cb);
void setButtonUpCallback(Callback cb);
void setRotateCWCallback(Callback cb);
void setRotateCCWCallback(Callback cb);
```

The callbacks must be no argument methods returning void.
The callbacks must be no argument methods returning void. The example sketches show how to use the library if you're using interrupts or polling. For polling to work the loop method must be called very often to catch the encoder transitions that indicate direction. In my experience delays of more than 10ms will cause it to miss the transition. The library attempts to detect this and make an educated guess about which direction the encoder was moving, but I'd really just recommend using a microcontroller that support interrupts. Multiple encoders are supported, see the examples included with the library to see how.

Usage with Interrupts
---------------------
See the library examples for complete working code.
```
void setup() {
encoder.setup();
encoder.setupInterrupts();
encoder.setButtonDownCallback(buttonDownCallback);
encoder.setButtonUpCallback(buttonUpCallback);
encoder.setRotateCWCallback(movedClockwiseCallback);
encoder.setRotateCCWCallback(movedCounterClockwiseCallback);
}
```

Usage with Polling
---------------------
See the library examples for complete working code.
```
void setup() {
encoder.setup();
encoder.setButtonDownCallback(buttonDownCallback);
encoder.setButtonUpCallback(buttonUpCallback);
encoder.setRotateCWCallback(movedClockwiseCallback);
encoder.setRotateCCWCallback(movedCounterClockwiseCallback);
}
void loop() {
encoder.loop();
}
```

Installation
------------
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "SimpleRotaryEncoder",
"keywords": "rotary encoder, esp8266",
"description": "ESP8266 Arduino IDE library for reading from rotary rotary encoders",
"keywords": "rotary encoder, incremental encoder, esp8266, arduino",
"description": "Arduino IDE library for reading an incremental rotary encoder, with a push button, with or without using interrupts, on an ESP8266, Arduino, or other Arduino IDE compatible board.",
"homepage": "https://github.com/sabeechen/SimpleRotaryEncoder",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name=Simple Rotary Encoder
version=1.0.0
author=Stephen Beechen
maintainer=Stephen Beechen <[email protected]>
sentence=ESP8266 Arduino IDE library for reading from rotary rotary encoders.
sentence=Arduino IDE library for reading an incremental rotary encoder, with a push button, with or without using interrupts, on an ESP8266, Arduino, or other Arduino IDE compatible board.
paragraph=Callbacks are used to handle events; one each for button up, button down, clockwise rotation and counter clockwise rotation.
category=Other
url=https://github.com/sabeechen/SimpleRotaryEncoder
Expand Down

0 comments on commit 95cbc9a

Please sign in to comment.