Skip to content

Commit 144a94b

Browse files
committed
v1.1
1 parent e894841 commit 144a94b

File tree

2 files changed

+3
-256
lines changed

2 files changed

+3
-256
lines changed

README.md

Lines changed: 2 additions & 255 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,7 @@ This will disable acceleration (now enabled by default) in case you dont need on
1414
Recomendation - turn off for small ranges; but turn on when you select from more than 50 values in range.
1515

1616

17-
# Arduino Esp32 / ESP8266 MULTIPLE Encoder Library
18-
19-
This project is based on the (https://github.com/igorantolic/ai-esp32-rotary-encoder) with only main difference that it supports
20-
multiple instances on encoders. Original library supported only one instance, but this project allows you to create more instance of encoders like this:
21-
22-
```c
23-
#include "AiEsp32RotaryEncoder.h"
24-
#define ROTARY_ENCODER2_A_PIN GPIO_NUM_16
25-
#define ROTARY_ENCODER2_B_PIN GPIO_NUM_4
26-
#define ROTARY_ENCODER1_A_PIN GPIO_NUM_17
27-
#define ROTARY_ENCODER1_B_PIN GPIO_NUM_5
28-
29-
AiEsp32RotaryEncoder rotaryEncoder1 = AiEsp32RotaryEncoder(ROTARY_ENCODER1_A_PIN, ROTARY_ENCODER1_B_PIN, -1, -1);
30-
AiEsp32RotaryEncoder rotaryEncoder2 = AiEsp32RotaryEncoder(ROTARY_ENCODER2_A_PIN, ROTARY_ENCODER2_B_PIN, -1, -1);
31-
```
32-
33-
in setup() of arduino:
34-
```c
35-
rotaryEncoder1.begin();
36-
rotaryEncoder1.setup([]{rotaryEncoder1.readEncoder_ISR();});
37-
38-
rotaryEncoder2.begin();
39-
rotaryEncoder2.setup([]{rotaryEncoder2.readEncoder_ISR();});
40-
```
17+
# Arduino Esp32 Encoder Library
4118

4219
Rotary encoder main interrupt code is extracted from (https://github.com/marcmerlin/IoTuz) and some additional features are included here.
4320

@@ -96,235 +73,5 @@ For ESP8266 you can use Dx as pin names like in example:
9673
```
9774
Then upload code to microcontroller.
9875

99-
This example is initally set that you can adjust values 0 to 10. If you try to go beyond upper limit 10, since cycle option is set to true, it will restart from 0. Also tryinf to adjust lower than 0 will go back to 10.
100-
101-
If you press button first time, new limits -2 ... 2 are set. But this time cycle is set to false, so you have real minimum and maximum values.
102-
103-
Further pressing button will double the same limit to -4 ... 4. Then -8...8 and so on. I wonder how far will you go. Real limt is int16 limit (signed int16) which should be sufficient for most applications.
104-
105-
## Details
106-
107-
### step 1) include library using
108-
109-
```c
110-
#include "AiEsp32RotaryEncoder.h"
111-
```
112-
113-
### step 2) set pins used. Important: A and B pins must support interrupts.
114-
115-
```c
116-
#define ROTARY_ENCODER_A_PIN 32
117-
#define ROTARY_ENCODER_B_PIN 21
118-
#define ROTARY_ENCODER_BUTTON_PIN 25
119-
#define ROTARY_ENCODER_VCC_PIN 27 /*put -1 of Rotary encoder Vcc is
120-
connected directly to 3,3V;
121-
else you can use declared output pin
122-
for powering rotary encoder */
123-
```
124-
125-
### step 3) declare your variable like rotaryEncoder
126-
127-
```c
128-
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
129-
ROTARY_ENCODER_A_PIN,
130-
ROTARY_ENCODER_B_PIN,
131-
ROTARY_ENCODER_BUTTON_PIN,
132-
ROTARY_ENCODER_VCC_PIN
133-
);
134-
```
135-
136-
### step 4) in setup() function you should call begin method to initialize encoder.
137-
138-
```c
139-
rotaryEncoder.begin();
140-
```
141-
142-
### step 4a) in setup() function you should call begin method to initialize encoder.
143-
144-
```c
145-
rotaryEncoder.setup([]{rotaryEncoder.readEncoder_ISR();});
146-
```
147-
148-
### step 5) in loop() call some function like rotary_loop();
149-
150-
```c
151-
rotary_loop();
152-
```
153-
154-
### step 6) define function rotary_loop()
155-
156-
Example:
157-
158-
```c
159-
160-
void rotary_loop() {
161-
//first lets handle rotary encoder button click
162-
if (rotaryEncoder.currentButtonState() == BUT_RELEASED) {
163-
//we can process it here or call separate function like:
164-
rotary_onButtonClick();
165-
}
166-
167-
//lets see if anything changed
168-
int8_t encoderDelta = rotaryEncoder.encoderChanged();
169-
170-
//optionally we can ignore whenever there is no change
171-
if (encoderDelta == 0) return;
172-
173-
//for some cases we only want to know if value is
174-
//increased or decreased (typically for menu items)
175-
if (encoderDelta>0) Serial.print("+");
176-
if (encoderDelta<0) Serial.print("-");
177-
178-
//for other cases we want to know what is current value.
179-
//Additionally often we only want if something changed
180-
//example: when using rotary encoder to set termostat temperature, or sound volume etc
181-
182-
//if value is changed compared to our last read
183-
if (encoderDelta!=0) {
184-
//now we need current value
185-
int16_t encoderValue = rotaryEncoder.readEncoder();
186-
187-
//process new value. Here is simple output.
188-
Serial.print("Value: ");
189-
Serial.println(encoderValue);
190-
191-
}
192-
}
193-
```
194-
195-
### step 7) if you use separate function for processing rotary encoder button click, implmement it
196-
197-
In step 6 we call rotary_onButtonClick();
198-
199-
example:
200-
201-
```c
202-
void rotary_onButtonClick() {
203-
204-
rotaryEncoder.disable();
205-
206-
}
207-
```
208-
209-
In this example we disable encoder on first click on button. Dont expect any further effects before you call
210-
211-
```c
212-
rotaryEncoder.enable();
213-
```
214-
215-
...for obvious reasons
216-
217-
## List of methods
218-
219-
### Constructor
220-
221-
222-
Call to define local variable. 4 parameters are pin numbers.
223-
```c
224-
#define ROTARY_ENCODER_A_PIN 32
225-
#define ROTARY_ENCODER_B_PIN 21
226-
#define ROTARY_ENCODER_BUTTON_PIN 25
227-
#define ROTARY_ENCODER_VCC_PIN 27
228-
229-
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
230-
ROTARY_ENCODER_A_PIN,
231-
ROTARY_ENCODER_B_PIN,
232-
ROTARY_ENCODER_BUTTON_PIN,
233-
ROTARY_ENCODER_VCC_PIN
234-
);
235-
//or empty constructor
236-
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder();
237-
/* Note: in case of empty constructor these are fefault pins:
238-
#define ROTARY_ENCODER_A_PIN 32
239-
#define ROTARY_ENCODER_B_PIN 21
240-
#define ROTARY_ENCODER_BUTTON_PIN 25
241-
#define ROTARY_ENCODER_VCC_PIN 27
242-
*/
243-
```
244-
245-
### setBoundaries (optional)
246-
247-
sets minimum and maximum value.
248-
Additionally set circleValues to false if you want to stop at min or max limits.
249-
If you want to min to continue with max value or vice versa set to true,
250-
251-
For example when using menu with 4 items you can call
252-
```c
253-
rotaryEncoder.setBoundaries(1,4,true);
254-
```
255-
rotating right will select valus 1, 2, 3, 4, 1 ,2, 3, ....
256-
257-
while rotating left will select valus 1, 4, 3,2,1,4,3, ....
258-
259-
### begin - initialization method
260-
261-
You must call this in setup()
262-
```c
263-
void setup() {
264-
rotaryEncoder.begin();
265-
//...
266-
}
267-
```
268-
269-
### reset to zero or selected value
270-
271-
selected value will change to selected value. If value not provided 0 is assumed.
272-
Please note that there is a limit check. If value is lower than low limit low limit will be set. The same is for maximum limit.
273-
274-
```c
275-
//reaset to 0
276-
rotaryEncoder.reset();
277-
//reaset to 3
278-
rotaryEncoder.reset(3);
279-
```
280-
281-
### disable and enable
282-
283-
This will disable rotary movement or button events. You must call enable to contunue getting new values or button clicks.
284-
```c
285-
rotaryEncoder.disable();
286-
rotaryEncoder.enable();
287-
```
288-
289-
290-
### readEncoder
291-
292-
This methot will fetch current value of encoder.
293-
```c
294-
int16_t currentValue = rotaryEncoder.readEncoder();
295-
```
296-
297-
### encoderChanged
298-
299-
This methot will return delta (absolute difference) comparing to previous read.
300-
```c
301-
//you can react only on changes
302-
int16_t encoderDelta = rotaryEncoder.encoderChanged();
303-
if (encoderDelta>0) Serial.print("+");
304-
if (encoderDelta<0) Serial.print("-");
305-
```
306-
307-
### currentButtonState
308-
309-
This methor returns value of enum - current button state
310-
```c
311-
ButtonState current = rotaryEncoder.currentButtonState();
312-
// or
313-
if (rotaryEncoder.currentButtonState() == BUT_RELEASED) {
314-
Serial.println("Click!");
315-
}
316-
317-
/*
318-
Button values are:
319-
typedef enum {
320-
BUT_DOWN = 0,
321-
BUT_PUSHED = 1,
322-
BUT_UP = 2,
323-
BUT_RELEASED = 3,
324-
BUT_DISABLED = 99, //this state is after you call rotaryEncoder.disable();
325-
} ButtonState;
326-
*/
327-
328-
```
329-
76+
README_old.md contains more information but some parts are obsolete.
33077

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Ai Esp32 Rotary Encoder
2-
version=1.0
2+
version=1.1
33
author=Igor Antolic (adapted code from github.com/marcmerlin/IoTuz)
44
maintainer=Igor Antolic <[email protected]>
55
sentence=Easy implement rotary encoder to your application

0 commit comments

Comments
 (0)