Arduino Helpers master
Utility library for Arduino
ShiftRegisterOut.ipp
Go to the documentation of this file.
3
5
6template <uint16_t N>
8 pin_t latchPin, BitOrder_t bitOrder)
9 : ShiftRegisterOutBase<N>(latchPin, bitOrder), dataPin(dataPin),
10 clockPin(clockPin) {}
11
12template <uint16_t N>
14 ExtIO::pinMode(dataPin, OUTPUT);
15 ExtIO::pinMode(clockPin, OUTPUT);
16 ExtIO::pinMode(this->latchPin, OUTPUT);
17 updateBufferedOutputs();
18}
19
20template <uint16_t N>
22 if (!this->dirty)
23 return;
24 ExtIO::digitalWrite(this->latchPin, LOW);
25 const uint8_t bufferLength = this->buffer.getBufferLength();
26 if (this->bitOrder == LSBFIRST)
27 for (uint8_t i = 0; i < bufferLength; i++)
28 ExtIO::shiftOut(dataPin, clockPin, LSBFIRST,
29 this->buffer.getByte(i));
30 else
31 for (int8_t i = bufferLength - 1; i >= 0; i--)
32 ExtIO::shiftOut(dataPin, clockPin, MSBFIRST,
33 this->buffer.getByte(i));
34
35 ExtIO::digitalWrite(this->latchPin, HIGH);
36 this->dirty = false;
37}
38
constexpr PinStatus_t LOW
uint8_t BitOrder_t
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
A class for serial-in/parallel-out shift registers, like the 74HC595.
void updateBufferedOutputs() override
Write the state buffer to the physical outputs.
ShiftRegisterOut(pin_t dataPin, pin_t clockPin, pin_t latchPin, BitOrder_t bitOrder=MSBFIRST)
Create a new ShiftRegisterOut object with a shift register connected to the given pins,...
void begin() override
Initialize the shift register.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void shiftOut(pin_t dataPin, pin_t clockPin, BitOrder_t bitOrder, uint8_t val)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.