InputEvents v1.5.2
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
ExpanderPinAdapter.h
1#ifndef ExpanderPinAdapter_h
2#define ExpanderPinAdapter_h
3
4#include "Arduino.h"
5#include "PinAdapter.h"
6#include "GpioExpanderAdapter/GpioExpanderAdapter.h"
7
13 public:
14
22 ExpanderPinAdapter(byte pin, GpioExpanderAdapter *expander, int mode = INPUT_PULLUP)
23 : pin(pin),
24 mode(mode),
25 expanderAdapter(expander)
26 {}
27
33 void begin() override {
34 if ( !expanderAdapter ) return;
35 expanderAdapter->attachPin(pin, mode);
36 }
37
44 bool read() override {
45 if ( !expanderAdapter ) return (mode == INPUT_PULLUP); //For safety, this should return the 'OFF' state based on pinMode
46 return expanderAdapter->read(pin);
47 }
48
49 private:
50 byte pin;
51 int mode;
52 GpioExpanderAdapter *expanderAdapter;
53};
54
55#endif
Implementation of a PinAdapter that reads from a GpioExpanderAdapter.
Definition: ExpanderPinAdapter.h:12
void begin() override
Attach the pin to the GpioExpanderAdapter which will set the pinMode if required/possible.
Definition: ExpanderPinAdapter.h:33
bool read() override
Return the state of this pin. If the GpioPinAdapter does not exist will return 'OFF' state (this shou...
Definition: ExpanderPinAdapter.h:44
ExpanderPinAdapter(byte pin, GpioExpanderAdapter *expander, int mode=INPUT_PULLUP)
Construct a new ExpanderPinAdapter with a GpioExpanderAdapter and optional pin mode (default INPUT_PU...
Definition: ExpanderPinAdapter.h:22
The base class/interface specification for GPIO expanders.
Definition: GpioExpanderAdapter.h:10
virtual bool read(byte pin)=0
Returns the state of a pin on the expander.
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.
The interface specification for button, encoder button and switch pins.
Definition: PinAdapter.h:8