3#ifndef INPUT_EVENTS_ADAFRUIT_MCP23017_EXPANDER_ADAPTERCP_H
4#define INPUT_EVENTS_ADAFRUIT_MCP23017_EXPANDER_ADAPTERCP_H
8#include <Adafruit_MCP23X17.h>
9#include "GpioExpanderAdapter/GpioExpanderAdapter.h"
10#include "PinAdapter/PinAdapter.h"
33 mcp =
new (&mcpStorage) Adafruit_MCP23X17();
51 delayMicroseconds(400);
52 pinStates = mcp->readGPIOAB();
63 bool begin(uint8_t i2c_addr, TwoWire *wire = &Wire) {
64 bool ret = mcp->begin_I2C(i2c_addr, wire);
65 delayMicroseconds(400);
66 pinStates = mcp->readGPIOAB();
76 pinStates = mcp->readGPIOAB();
85 void attachPin(
byte pin,
int mode = INPUT_PULLUP)
override {
86 mcp->pinMode(pin, mode);
97 bool read(
byte pin)
override {
98 return bitRead(pinStates, pin);
109 return mcp->digitalRead(pin);
121 mcp->digitalWrite(pin, state);
135 alignas(Adafruit_MCP23X17) uint8_t mcpStorage[
sizeof(Adafruit_MCP23X17)];
136 Adafruit_MCP23X17* mcp;
137 uint16_t pinStates = 0;
An implementation of the GpioExpanderAdapter For Adafruit's MCP23017 library.
Definition: AdafruitMCP23017ExpanderAdapter.h:18
bool canWrite()
The MCP23017 can write a pins state.
Definition: AdafruitMCP23017ExpanderAdapter.h:129
bool begin(uint8_t i2c_addr, TwoWire *wire=&Wire)
Use this method instead of the default begin() to specify a different I2C addreess and optional Wire.
Definition: AdafruitMCP23017ExpanderAdapter.h:63
bool read(byte pin) override
Returns the state of a pin on the expander.
Definition: AdafruitMCP23017ExpanderAdapter.h:97
bool updateAndRead(byte pin)
Update the expander over I2C and return a pin state. Not recommended, use a single uptate() and then ...
Definition: AdafruitMCP23017ExpanderAdapter.h:108
void update() override
Update the state of all input pins (called from loop() before updating EventButtons)
Definition: AdafruitMCP23017ExpanderAdapter.h:75
AdafruitMCP23017ExpanderAdapter(Adafruit_MCP23X17 &_mcp)
Construct a AdafruitMCP23017ExpanderAdapter with an already created Adafruit_MCP23X17 instance.
Definition: AdafruitMCP23017ExpanderAdapter.h:41
void begin() override
The default begin for a GPIOExpanderAdapter will use the default I2C address for the MCP23017.
Definition: AdafruitMCP23017ExpanderAdapter.h:49
void attachPin(byte pin, int mode=INPUT_PULLUP) override
Attach a pin and set its pin mode.
Definition: AdafruitMCP23017ExpanderAdapter.h:85
AdafruitMCP23017ExpanderAdapter()
Construct a AdafruitMCP23017ExpanderAdapter. An Adafruit_MCP23X17 instance will be created for you.
Definition: AdafruitMCP23017ExpanderAdapter.h:29
void write(byte pin, bool state)
Write bool state to a pin.
Definition: AdafruitMCP23017ExpanderAdapter.h:120
The base class/interface specification for GPIO expanders.
Definition: GpioExpanderAdapter.h:10