InputEvents v1.5.2
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
RobTillaartPCF8575ExpanderAdapter.h
1// #ifdef __ADAFRUIT_MCP23XXX_H__
2
3#ifndef RobTillaartPCF8575ExpanderAdapter_h
4#define RobTillaartPCF8575ExpanderAdapter_h
5
6#include "Arduino.h"
7#include <PCF8575.h>
8#include "GpioExpanderAdapter/GpioExpanderAdapter.h"
9#include "PinAdapter/PinAdapter.h"
10
20
21public:
22
28 : pcf(0x20)
29 {}
30
37 RobTillaartPCF8575ExpanderAdapter(const uint8_t deviceAddress, TwoWire *wire = &Wire)
38 : pcf(deviceAddress, wire)
39 {}
40
47 : pcf(_pcf)
48 {}
49
54 void begin() override {
55 pcf.begin();
56 delayMicroseconds(400);
57 pinStates = pcf.read16();
58 }
59
64 void update() override {
65 pinStates = pcf.read16();
66 }
67
74 void attachPin(byte pin, int mode = INPUT_PULLUP) override {
75
76 }
77
85 bool read(byte pin) override {
86 return bitRead(pinStates, pin);
87 //return pcf.read(pin);
88 }
89
97 bool updateAndRead(byte pin) {
98 return pcf.read(pin);
99 }
100
107 void write(byte pin, bool state) {
108 }
109
115 bool canWrite() { return true; }
116
117 virtual ~RobTillaartPCF8575ExpanderAdapter() = default;
118
119private:
120
121 PCF8575 pcf;
122 uint16_t pinStates = 0;
123};
124
125
126#endif
127// #endif
The base class/interface specification for GPIO expanders.
Definition: GpioExpanderAdapter.h:10
An implementation of the GpioExpanderAdapter RobTillaart's PCF8575 library.
Definition: RobTillaartPCF8575ExpanderAdapter.h:19
bool read(byte pin) override
Returns the state of a pin on the expander.
Definition: RobTillaartPCF8575ExpanderAdapter.h:85
bool updateAndRead(byte pin)
Update the expander over I2C and return a pin state. Not recommended, use a single uptate() and then ...
Definition: RobTillaartPCF8575ExpanderAdapter.h:97
void attachPin(byte pin, int mode=INPUT_PULLUP) override
Attach a pin and set its pin mode.
Definition: RobTillaartPCF8575ExpanderAdapter.h:74
void update() override
Update the state of all input pins (called from loop() before updating EventButtons)
Definition: RobTillaartPCF8575ExpanderAdapter.h:64
void begin() override
The default begin for a GPIOExpanderAdapter.
Definition: RobTillaartPCF8575ExpanderAdapter.h:54
bool canWrite()
The MCP23017 can write a pins state.
Definition: RobTillaartPCF8575ExpanderAdapter.h:115
RobTillaartPCF8575ExpanderAdapter(const uint8_t deviceAddress, TwoWire *wire=&Wire)
Construct a RobTillaartPCF8575ExpanderAdapter using a specified I2C address and otional Wire.
Definition: RobTillaartPCF8575ExpanderAdapter.h:37
RobTillaartPCF8575ExpanderAdapter()
Construct a RobTillaartPCF8575ExpanderAdapter using the default I2C address.
Definition: RobTillaartPCF8575ExpanderAdapter.h:27
RobTillaartPCF8575ExpanderAdapter(PCF8575 &_pcf)
Construct a RobTillaartPCF8575ExpanderAdapter using an already created PCF8575 instance.
Definition: RobTillaartPCF8575ExpanderAdapter.h:46
void write(byte pin, bool state)
Write bool state to a pin.
Definition: RobTillaartPCF8575ExpanderAdapter.h:107