3#ifndef AdafruitMCP23017ExpanderAdapter_h
4#define AdafruitMCP23017ExpanderAdapter_h
6#include <Adafruit_MCP23X17.h>
8#include "GpioExpanderAdapter/GpioExpanderAdapter.h"
9#include "PinAdapter/PinAdapter.h"
42 delayMicroseconds(400);
43 pinStates = mcp.readGPIOAB();
54 bool begin(uint8_t i2c_addr, TwoWire *wire = &Wire) {
55 bool ret = mcp.begin_I2C(i2c_addr, wire);
56 delayMicroseconds(400);
57 pinStates = mcp.readGPIOAB();
67 pinStates = mcp.readGPIOAB();
76 void attachPin(
byte pin,
int mode = INPUT_PULLUP)
override {
77 mcp.pinMode(pin, mode);
88 bool read(
byte pin)
override {
89 return bitRead(pinStates, pin);
100 return mcp.digitalRead(pin);
112 mcp.digitalWrite(pin, state);
126 Adafruit_MCP23X17 mcp;
127 uint16_t pinStates = 0;
An implementation of the GpioExpanderAdapter For Adafruit's MCP23017 library.
Definition: AdafruitMCP23017ExpanderAdapter.h:17
bool canWrite()
The MCP23017 can write a pins state.
Definition: AdafruitMCP23017ExpanderAdapter.h:120
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:54
bool read(byte pin) override
Returns the state of a pin on the expander.
Definition: AdafruitMCP23017ExpanderAdapter.h:88
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:99
void update() override
Update the state of all input pins (called from loop() before updating EventButtons)
Definition: AdafruitMCP23017ExpanderAdapter.h:66
AdafruitMCP23017ExpanderAdapter(Adafruit_MCP23X17 &_mcp)
Construct a AdafruitMCP23017ExpanderAdapter with an already created Adafruit_MCP23X17 instance.
Definition: AdafruitMCP23017ExpanderAdapter.h:32
void begin() override
The default begin for a GPIOExpanderAdapter will use the default I2C address for the MCP23017.
Definition: AdafruitMCP23017ExpanderAdapter.h:40
void attachPin(byte pin, int mode=INPUT_PULLUP) override
Attach a pin and set its pin mode.
Definition: AdafruitMCP23017ExpanderAdapter.h:76
AdafruitMCP23017ExpanderAdapter()
Construct a AdafruitMCP23017ExpanderAdapter. An Adafruit_MCP23X17 instance will be created for you.
Definition: AdafruitMCP23017ExpanderAdapter.h:25
void write(byte pin, bool state)
Write bool state to a pin.
Definition: AdafruitMCP23017ExpanderAdapter.h:111
The base class/interface specification for GPIO expanders.
Definition: GpioExpanderAdapter.h:10