InputEvents v1.6.0
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
ExpanderPinAdapter.h
1#ifndef INPUT_EVENTS_EXPANDER_PIN_ADAPTER_H
2#define INPUT_EVENTS_EXPANDER_PIN_ADAPTER_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
35 void begin() override {
36 if ( !expanderAdapter ) return;
37 expanderAdapter->attachPin(pin, mode);
38 }
39
46 bool read() override {
47 if ( !expanderAdapter ) return (mode == INPUT_PULLUP); //For safety, this should return the 'OFF' state based on pinMode
48 return expanderAdapter->read(pin);
49 }
50
51 private:
52 byte pin;
53 int mode;
54 GpioExpanderAdapter* expanderAdapter;
55};
56
57#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:35
bool read() override
Return the state of this pin. If the GpioPinAdapter does not exist will return 'OFF' state (this shou...
Definition: ExpanderPinAdapter.h:46
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