[Lib] ShiftRegister74HC595_NT: Add setSize() method, cleanup constructor

This commit is contained in:
Ton Huisman
2022-01-22 14:01:09 +01:00
parent 5f4c543122
commit c583a65894
2 changed files with 15 additions and 11 deletions
@@ -21,22 +21,19 @@
ShiftRegister74HC595_NonTemplate::ShiftRegister74HC595_NonTemplate(const uint8_t size,
const uint8_t serialDataPin,
const uint8_t clockPin,
const uint8_t latchPin) {
const uint8_t latchPin) :
// set attributes
_size = size;
_clockPin = clockPin;
_serialDataPin = serialDataPin;
_latchPin = latchPin;
_size(size), _clockPin(clockPin), _serialDataPin(serialDataPin), _latchPin(latchPin) {
// define pins as outputs
pinMode(clockPin, OUTPUT);
pinMode(serialDataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(_clockPin, OUTPUT);
pinMode(_serialDataPin, OUTPUT);
pinMode(_latchPin, OUTPUT);
// set pins low
digitalWrite(clockPin, LOW);
digitalWrite(serialDataPin, LOW);
digitalWrite(latchPin, LOW);
digitalWrite(_clockPin, LOW);
digitalWrite(_serialDataPin, LOW);
digitalWrite(_latchPin, LOW);
// allocates the specified number of bytes and initializes them to zero
_digitalValues.resize(_size, 0);
@@ -45,6 +42,12 @@ ShiftRegister74HC595_NonTemplate::ShiftRegister74HC595_NonTemplate(const uint8_t
// updateRegisters(); // reset shift register
}
// Set a new size for the mnumber of shift registers
void ShiftRegister74HC595_NonTemplate::setSize(const uint8_t size) {
_size = size;
_digitalValues.resize(_size, 0); // Reset new values to 0 when enlarging
}
// Set all pins of the shift registers at once. Do not yet update the registers if update is false
// digitalVAlues is a uint8_t array where the length is equal to the number of shift registers.
void ShiftRegister74HC595_NonTemplate::setAll(const uint8_t *digitalValues, bool update) {
@@ -18,6 +18,7 @@ public:
const uint8_t clockPin,
const uint8_t latchPin);
void setSize(const uint8_t size);
void setAll(const uint8_t *digitalValues,
bool update = true);
const uint8_t* getAll() const;