Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions SevSegShift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
#include <SevSegShift.h>


// constructor implementation
SevSegShift::SevSegShift(
byte pinDS,
Expand All @@ -46,6 +45,16 @@ SevSegShift::SevSegShift(
_shiftRegisterMap = new byte[8*numberOfShiftRegisters];
_numberOfShiftRegisters = numberOfShiftRegisters;
_isDigitsOnController = isDigitsOnController;

_shiftRegisterMapDigits = nullptr;
_shiftRegisterMapSegments = nullptr;
}

SevSegShift::~SevSegShift()
{
delete _shiftRegisterMap;
delete _shiftRegisterMapDigits;
delete _shiftRegisterMapSegments;
}

void SevSegShift::begin(
Expand All @@ -58,12 +67,33 @@ void SevSegShift::begin(
bool leadingZerosIn,
bool disableDecPoint
) {
// NOTE: Code duplication to SevSeg::begin
// We need to calculate numDigits and numSegments here for allocating the maps
// We cannot move the SevSeg::begin call up, since it calls segmentOff, which in
// turn relies on everything being setup (incl. _shiftRegisterMapSegments)
numDigits = numDigitsIn;
numSegments = disableDecPoint ? 7 : 8; // Ternary 'if' statement
//Limit the max number of digits to prevent overflowing
if (numDigits > MAXNUMDIGITS) numDigits = MAXNUMDIGITS;

// Remove old data if begin is called multiple times on same object
delete _shiftRegisterMapDigits;
delete _shiftRegisterMapSegments;

// here the digit"pins" of the Shift register is stored
// pins are here the OUTPUT PINs of the Shift Register
_shiftRegisterMapDigits = shiftRegisterMapDigits;
_shiftRegisterMapDigits = new byte[numDigitsIn];
for (int i = 0; i < numDigitsIn; ++i)
{
_shiftRegisterMapDigits[i] = shiftRegisterMapDigits[i];
}
// here the segment"pins" of the Shift register is stored
// pins are here the OUTPUT PINs of the Shift Register
_shiftRegisterMapSegments = shiftRegisterMapSegments;
_shiftRegisterMapSegments = new byte[numSegments];
for (int i = 0; i < numSegments; ++i)
{
_shiftRegisterMapSegments[i] = shiftRegisterMapSegments[i];
}

// dummy port for initialization (pin of DS is used - and will be set for OUTPUT multiple times ;) )
byte dummyDigitPINs[8] = {_pinDS,_pinDS,_pinDS,_pinDS,_pinDS,_pinDS,_pinDS,_pinDS};
Expand All @@ -85,7 +115,6 @@ void SevSegShift::begin(
updateWithDelaysIn,
leadingZerosIn,
disableDecPoint);

}

// segmentOn
Expand Down
1 change: 1 addition & 0 deletions SevSegShift.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SevSegShift: public SevSeg {
const byte numberOfShiftRegisters = 2, // currently const value (not changeable) - maybe in future
bool isDigitsOnController=false // only Segments are on ShiftRegister - DigitPins are connected to controller
);
virtual ~SevSegShift();

/*
prepare the SevenSeg-Shift-Register lib
Expand Down