An I2C wrapper class for quadrature rotary sensors which uses the RotaryEncoder library by Matthias Hertel.
More...
An I2C wrapper class for quadrature rotary sensors which uses the RotaryEncoder library by Matthias Hertel.
Each rotary sensor is represented by an I2Cwrapper unit. Supports up to 2 sensors on ATtiny85, 8 sensors otherwise.
|
| RotaryEncoderI2C (I2Cwrapper *w) |
| Constructor. More...
|
|
int8_t | attach (int pin1, int pin2, RotaryEncoder::LatchMode mode=RotaryEncoder::LatchMode::FOUR0) |
| Replaces the RotaryEncoder constructor and takes the same arguments. Will allocate an RotaryEncoder object on the target's side and make it ready for use. Does not return an success/error result. Instead check myNum >= 0 to see if the target successfully added the encoder. If not, it's -1. More...
|
|
long | getPosition () |
|
RotaryEncoder::Direction | getDirection () |
| Important: In normal RotaryEncounter, direction will be the direction during at the moment of the last tick(). It will thus correspond with the getPosition() reading. In I2C mode, the target will tick() on its own. So the direction will be more current than in normal mode and may seem to contradict the position reading. Needs fixing. More...
|
|
void | setPosition (long newPosition) |
|
unsigned long | getMillisBetweenRotations () const |
|
unsigned long | getRPM () |
| Note that I think getRPM() is not functional in the original library, as it assumes a fixed number of 20 pulses per rotation. See this issue More...
|
|
void | startDiagnosticsMode (uint8_t numEncoder=0) |
| Puts device in a diagnostics mode which is meant for analysing your quadrature signal. After calling this, the device will not accept any commands anymore (so don't send any after that), it will just serve onRequest() events and reply to them by sending one single byte which contains the current pin state of the selected encoders' two input pins. Use getDiagnostics() for that. You'll need to reset the device to put it back in normal mode. More...
|
|
uint8_t | getDiagnostics () |
| Use only in diagnostics mode to read the status of the two input pins of your chosen attached encoder. More...
|
|
◆ RotaryEncoderI2C()
RotaryEncoderI2C::RotaryEncoderI2C |
( |
I2Cwrapper * |
w | ) |
|
Constructor.
- Parameters
-
w | Wrapper object representing the target the pin is connected to. |
◆ attach()
int8_t RotaryEncoderI2C::attach |
( |
int |
pin1, |
|
|
int |
pin2, |
|
|
RotaryEncoder::LatchMode |
mode = RotaryEncoder::LatchMode::FOUR0 |
|
) |
| |
Replaces the RotaryEncoder constructor and takes the same arguments. Will allocate an RotaryEncoder object on the target's side and make it ready for use. Does not return an success/error result. Instead check myNum >= 0 to see if the target successfully added the encoder. If not, it's -1.
- Parameters
-
pin1,pin2,pin3,mode | see original library |
- Returns
- total number of attached encoders including this one, -1 in case of error (= limit of attachable encoders exceeded)
◆ getDiagnostics()
uint8_t RotaryEncoderI2C::getDiagnostics |
( |
| ) |
|
Use only in diagnostics mode to read the status of the two input pins of your chosen attached encoder.
- Returns
- (pin1 | (pin2 << 1)) of the encoder you chose in startDiagnosticsMode(); 0xFF in case of error
- See also
- startDiagnosticsMode()
◆ getDirection()
RotaryEncoder::Direction RotaryEncoderI2C::getDirection |
( |
| ) |
|
Important: In normal RotaryEncounter, direction will be the direction during at the moment of the last tick(). It will thus correspond with the getPosition() reading. In I2C mode, the target will tick() on its own. So the direction will be more current than in normal mode and may seem to contradict the position reading. Needs fixing.
- Returns
- NOROTATION = 0, CLOCKWISE = 1, COUNTERCLOCKWISE = -1
◆ getMillisBetweenRotations()
unsigned long RotaryEncoderI2C::getMillisBetweenRotations |
( |
| ) |
const |
◆ getPosition()
long RotaryEncoderI2C::getPosition |
( |
| ) |
|
◆ getRPM()
unsigned long RotaryEncoderI2C::getRPM |
( |
| ) |
|
Note that I think getRPM() is not functional in the original library, as it assumes a fixed number of 20 pulses per rotation. See this issue
- Returns
- (probably wrong) RPM
◆ setPosition()
void RotaryEncoderI2C::setPosition |
( |
long |
newPosition | ) |
|
◆ startDiagnosticsMode()
void RotaryEncoderI2C::startDiagnosticsMode |
( |
uint8_t |
numEncoder = 0 | ) |
|
Puts device in a diagnostics mode which is meant for analysing your quadrature signal. After calling this, the device will not accept any commands anymore (so don't send any after that), it will just serve onRequest() events and reply to them by sending one single byte which contains the current pin state of the selected encoders' two input pins. Use getDiagnostics() for that. You'll need to reset the device to put it back in normal mode.
- Parameters
-
numEncoder | number of the encoder to diagnose, default is the first one |
- See also
- getDiagnostics()
- Note
- ESP32's weird I2C target implementation could break this, so be warned that diagnostics mode might not work on this platform.
◆ myNum
int8_t RotaryEncoderI2C::myNum = -1 |
The documentation for this class was generated from the following files: