31template <
class WireType,
class EncoderPositionType = int32_t,
32 bool InterruptSafe =
false>
35 constexpr static uint8_t I2C_BASE_ADDRESS = 0x20;
50 this->wire->beginTransmission(address);
51 this->wire->write(values, N);
52 this->wire->endTransmission();
63 template <
class...
Args>
81 this->wire->requestFrom(address,
size_t(2));
107 pin_t interrupt_pin = NO_PIN)
108 : wire(&wire), address(I2C_BASE_ADDRESS |
addr_offset),
109 interrupt_pin(interrupt_pin) {}
156 if (interrupt_pin != NO_PIN)
166 encs.reset(readGPIO());
181 if (interrupt_pin != NO_PIN &&
182 ExtIO::digitalRead(interrupt_pin) ==
HIGH)
212 return encs.readAndReset(
idx);
#define BEGIN_AH_NAMESPACE
constexpr PinStatus_t HIGH
constexpr PinMode_t INPUT_PULLUP
Class for reading 8 rotary encoders using a MCP23017 I²C port expander.
MCP23017Encoders(WireType &wire, uint8_t addr_offset=0, pin_t interrupt_pin=NO_PIN)
Constructor.
typename RegisterEncoderType::Encoder MCP23017Encoder
Proxy to access a single encoder of the 8 encoders managed by MCP23017Encoders.
EncoderPositionType read(uint8_t idx) const
Read the position of the given encoder.
uint16_t readGPIO()
Read the state of all GPIO pins.
void begin()
Initialize the MCP23017.
MCP23017Encoder operator[](uint8_t index)
Get a proxy to one of the encoders managed by this MCP23017.
EncoderPositionType readAndReset(uint8_t idx)
Read the position of the given encoder and reset it to zero.
void update()
If the state of the MCP23017's GPIO changed, read the new state and update the encoder positions.
void writeI2C(uint8_t addr, Args... values)
Write any data to the MCP23017.
void write(uint8_t idx, EncoderPositionType pos)
Set the position of the given encoder.
void writeI2C(const uint8_t(&values)[N])
Write any data to the MCP23017.
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...