@@ -16,92 +16,111 @@ Arduino library for a PCF8574 based rotary decoder - supports 4 rotary encoders.
1616
1717## Description
1818
19- This experimental library uses a PCF8574 to read the pulses of a rotary encoder.
19+ This library uses a PCF8574 to read the pulses of a rotary encoder.
2020As a PCF8574 has 8 lines up to 4 decoders can be read over I2C.
2121The PCF interrupt line can be used to detect changes in the position of the encoders.
2222
2323If less than 4 rotary encoders are connected one should use the lower bit lines as the
2424library assumes these are used. Furthermore it is advised to connect the free PCF8574
2525pins to GND so you will not get unintended interrupts.
2626
27+ Note: This library works (limited) with the PCF8575.
2728
28- #### Related
29+ As always, feedback is welcome.
2930
31+
32+ ### Related
33+
34+ - https://github.com/RobTillaart/rotaryDecoder
3035- https://github.com/RobTillaart/rotaryDecoderSwitch
36+ - https://github.com/RobTillaart/rotaryDecoder8
37+ - https://github.com/RobTillaart/rotaryDecoderSwitch5
3138- https://github.com/RobTillaart/PCF8574
39+ - https://github.com/RobTillaart/PCF8575
3240
3341
3442## Interface
3543
3644``` cpp
37- #include " rotaryEncoder .h"
45+ #include " rotaryDecoder .h"
3846```
3947
40- #### Constructor
48+ ### Constructor
4149
4250- ** rotaryDecoder(const int8_t address, TwoWire \* wire = Wire)**
4351constructor to set the address and optional the Wire bus.
4452- ** bool begin(uint8_t count = 4)** UNO ea. initializes the class.
4553count is the number of rotary encoders connected. (Max 4 per PCF8574)
4654Returns true if the PCF8574 is on the I2C bus.
4755- ** bool isConnected()** returns true if the PCF8574 is on the I2C bus.
56+ - ** uint8_t getRECount()** returns number of RE's from begin(),
57+ convenience e.g. for for loops.
58+ - ** void reset()** reset all internal counters to 0.
4859
49-
50- #### Core functions
60+ ### Core functions
5161
5262- ** uint8_t readInitialState()** read the initial state of the 4 rotary encoders.
5363Typically called in setup only, or after a sleep e.g. in combination with ** setValue()** .
54- Since 0.3.1 this function returns the read state, saves an additional read8() call.
64+ This function returns the read state, saves an additional read8() call.
5565- ** bool checkChange()** used for polling to see if one or more RE have changed.
5666This function does NOT update the internal counters.
5767- ** bool update()** returns true if there is a change detected.
5868It updates the internal counters of the RE.
5969The counters will add +1 or -1 depending on rotation direction.
60- Need to be called before ** getValue()** or before ** getKeyPressed() ** .
70+ Need to be called before ** getValue()** .
6171Note that ** update()** must be called as soon as possible after the interrupt occurs
6272or as often as possible when polling.
6373Returns false if there is no change since last read.
6474- ** bool updateSingle()** returns true if there is a change detected.
6575It updates the internal counters of the RE.
6676This will add +1, +2 or +3 as it assumes that the rotary encoder
67- only goes into a single direction.
77+ only goes into a single direction.
78+ Typical use is for a RPM measurement.
79+ Note that the ** getValue()** can go 3x as fast if you turn in the other direction.
6880Returns false if there is no change since last read.
6981
7082
71- #### Counters
83+ ### Counters
7284
7385- ** int32_t getValue(uint8_r re)** returns the RE counter.
7486If the parameter re > 3 then 0 is returned.
87+ The max value is ± 2147483647.
7588- ** bool setValue(uint8_r re, int32_t value = 0)** (re)set the internal counter to value, default 0.
7689If the parameter re > 3 then false is returned, true otherwise.
7790
7891
79- #### Read1 - Write1 - experimental
92+ ### Read1 - Write1
8093
81- Warning the ** write1(pin, value)** might alter the state of the rotary encoder pins.
94+ ** Warning**
95+
96+ The ** write1(pin, value)** might alter the state of the rotary encoder pins.
8297So this functionality should be tested thoroughly for your application.
83- Especially the ** write ()** is ** experimental** , see issue # 10 , feedback welcome.
98+ Especially the ** write1 ()** is ** experimental** , feedback welcome.
8499
85- See example ** rotaryDecoder_demo_RE_IO.ino** (since 0.3.1) .
100+ See example ** rotaryDecoder_demo_RE_IO.ino** .
86101
87102** Read1()** and ** write1()** are functions to access the pins of the PCF8574 that
88103are not used for rotary encoders.
89- The user must guard that especially writing the pins do not interfere with the rotary encoder pins.
104+ The user must guard that especially writing the pins do not interfere with the
105+ rotary encoder pins.
90106
91107- ** uint8_t read1(uint8_t pin)** reads a single pin (0..7).
92108Returns HIGH or LOW.
93109- ** bool write1(uint8_t pin, uint8_t value)** writes a single pin (0..7).
94110Value should be LOW (0) or HIGH (other values).
111+ As said before the user must guard not to interfere with the
112+ rotary encoder pins.
95113- ** uint8_t read8()** read all pins in one I2C IO action. When one need to access multiple
96114input pins this is faster but need some bit masking.
97- - ** bool write8(uint8_t value )** writes to multiple pins at once, e.g. to control multiple
115+ - ** bool write8(uint8_t bitmask )** writes to multiple pins at once, e.g. to control multiple
98116LEDs in one IO action. As said before the user must guard not to interfere with the
99117rotary encoder pins.
100118
101119
102- #### Debugging
120+ ### Debugging
103121
104- - ** int8_t getLastPosition(uint8_r re)** Returns last position.
122+ - ** int8_t getLastPosition(uint8_r re)** Returns last position.
123+ Returns 0 if re > 3.
105124
106125
107126## Performance
@@ -143,6 +162,7 @@ assuming 4 pulses == 360
143162
144163- update documentation
145164- picture how to connect e.g two rotary encoders which pins to used
165+ - keep in sync with rotaryEncoder8 (PCF8575) class.
146166
147167#### Should
148168
@@ -153,6 +173,7 @@ assuming 4 pulses == 360
153173- invert flag to adjust to RE that give their pulse just the other way around?
154174 - setInvert(bool); getInvert();
155175 - per channel / all?
176+ - split ** reset()** per var?
156177
157178#### Wont
158179
0 commit comments