1#ifndef HC165ExpanderAdapter_h
2#define HC165ExpanderAdapter_h
5#include "GpioExpanderAdapter/GpioExpanderAdapter.h"
6#include "PinAdapter/PinAdapter.h"
19 static const int cascadeDefaultLength = 1;
20 static const int cascadeMaxLength = 4;
21 static const int piPinCount = 8;
36 cascadeLength(cascadeLength)
38 cascadeLength = cascadeLength > cascadeMaxLength ? cascadeMaxLength : cascadeLength;
46 pinMode(dataPin, INPUT);
47 pinMode(clockPin, OUTPUT);
48 pinMode(shldPin, OUTPUT);
57 digitalWrite(shldPin, LOW);
58 digitalWrite(shldPin, HIGH);
61 for (
int i = 0; i < cascadeLength * piPinCount; i++) {
62 int pin = digitalRead(dataPin);
69 digitalWrite(clockPin, HIGH);
70 digitalWrite(clockPin, LOW);
80 bool read(
byte pin)
override {
81 return bitRead(pins, pin);
90 void attachPin(
byte pin,
int mode = INPUT_PULLUP)
override {}
The base class/interface specification for GPIO expanders.
Definition: GpioExpanderAdapter.h:10
An implementation of the GpioExpanderAdapter using 74HC165 shift register(s)
Definition: HC165ExpanderAdapter.h:18
void update() override
Read the state of pins on the 74HC165 cascade.
Definition: HC165ExpanderAdapter.h:55
bool read(byte pin) override
Returns the state of a pin on the expander.
Definition: HC165ExpanderAdapter.h:80
void begin() override
Initialize the pin expander.
Definition: HC165ExpanderAdapter.h:45
HC165ExpanderAdapter(byte dataPin, byte clockPin, byte shldPin, byte cascadeLength=cascadeDefaultLength)
Construct a new HC165ExpanderAdapter.
Definition: HC165ExpanderAdapter.h:32
void attachPin(byte pin, int mode=INPUT_PULLUP) override
pinMode not supported by 74HC165 so do nothing
Definition: HC165ExpanderAdapter.h:90