InputEvents v1.5.2
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
Public Member Functions | List of all members
AdafruitMCP23017ExpanderAdapter Class Reference

Description

An implementation of the GpioExpanderAdapter For Adafruit's MCP23017 library.

Details: https://learn.adafruit.com/adafruit-mcp23017-i2c-gpio-expander *

#include <AdafruitMCP23017ExpanderAdapter.h>

Inheritance diagram for AdafruitMCP23017ExpanderAdapter:
Inheritance graph
[legend]

Public Member Functions

 AdafruitMCP23017ExpanderAdapter ()
 Construct a AdafruitMCP23017ExpanderAdapter. An Adafruit_MCP23X17 instance will be created for you.
 
 AdafruitMCP23017ExpanderAdapter (Adafruit_MCP23X17 &_mcp)
 Construct a AdafruitMCP23017ExpanderAdapter with an already created Adafruit_MCP23X17 instance. More...
 
void begin () override
 The default begin for a GPIOExpanderAdapter will use the default I2C address for the MCP23017. More...
 
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. More...
 
void update () override
 Update the state of all input pins (called from loop() before updating EventButtons) More...
 
void attachPin (byte pin, int mode=INPUT_PULLUP) override
 Attach a pin and set its pin mode. More...
 
bool read (byte pin) override
 Returns the state of a pin on the expander. More...
 
bool updateAndRead (byte pin)
 Update the expander over I2C and return a pin state. Not recommended, use a single uptate() and then multiple pin read()s in loop(). More...
 
void write (byte pin, bool state)
 Write bool state to a pin. More...
 
bool canWrite ()
 The MCP23017 can write a pins state. More...
 
- Public Member Functions inherited from GpioExpanderAdapter
virtual void begin ()=0
 Initialize the expander. (Idempotent) More...
 
virtual void update ()=0
 Read the state of all pins on the expander. More...
 
virtual bool read (byte pin)=0
 Returns the state of a pin on the expander. More...
 
virtual void attachPin (byte pin, int mode=INPUT_PULLUP)=0
 Use it to configure individual pin mode, if expander allows it. Not all of them do. More...
 
void write (byte pin, bool state)
 Optionally implemented by concrete GpioExpanderAdapters if they support writing to pins. More...
 
bool canWrite ()
 Returns true if the concrete GpioExpanderAdapter has implemented the write() method. More...
 

Constructor & Destructor Documentation

◆ AdafruitMCP23017ExpanderAdapter()

AdafruitMCP23017ExpanderAdapter::AdafruitMCP23017ExpanderAdapter ( Adafruit_MCP23X17 &  _mcp)
inline

Construct a AdafruitMCP23017ExpanderAdapter with an already created Adafruit_MCP23X17 instance.

Parameters
_mcp

Member Function Documentation

◆ attachPin()

void AdafruitMCP23017ExpanderAdapter::attachPin ( byte  pin,
int  mode = INPUT_PULLUP 
)
inlineoverridevirtual

Attach a pin and set its pin mode.

Parameters
pinThe pin number on the expander
modeDefault INPUT_PULLUP

Implements GpioExpanderAdapter.

◆ begin() [1/2]

void AdafruitMCP23017ExpanderAdapter::begin ( )
inlineoverridevirtual

The default begin for a GPIOExpanderAdapter will use the default I2C address for the MCP23017.

Implements GpioExpanderAdapter.

◆ begin() [2/2]

bool AdafruitMCP23017ExpanderAdapter::begin ( uint8_t  i2c_addr,
TwoWire *  wire = &Wire 
)
inline

Use this method instead of the default begin() to specify a different I2C addreess and optional Wire.

Parameters
i2c_addrThe I2C address to use for the MCP23017
wireOptional
Returns
true
false

◆ canWrite()

bool AdafruitMCP23017ExpanderAdapter::canWrite ( )
inline

The MCP23017 can write a pins state.

Returns
true

◆ read()

bool AdafruitMCP23017ExpanderAdapter::read ( byte  pin)
inlineoverridevirtual

Returns the state of a pin on the expander.

Parameters
pinThe pin number on the expander board
Returns
true/HIGH
false/LOW

Implements GpioExpanderAdapter.

◆ update()

void AdafruitMCP23017ExpanderAdapter::update ( )
inlineoverridevirtual

Update the state of all input pins (called from loop() before updating EventButtons)

Implements GpioExpanderAdapter.

◆ updateAndRead()

bool AdafruitMCP23017ExpanderAdapter::updateAndRead ( byte  pin)
inline

Update the expander over I2C and return a pin state. Not recommended, use a single uptate() and then multiple pin read()s in loop().

Parameters
pinThe pin number on the expander board
Returns
true/HIGH
false/LOW

◆ write()

void AdafruitMCP23017ExpanderAdapter::write ( byte  pin,
bool  state 
)
inline

Write bool state to a pin.

Sets the pin state directlu over I2C

Parameters
pinThe pin number on the expander
statetrue/false or HIGH/LOW

The documentation for this class was generated from the following file: