Skip to content

Commit

Permalink
Cleaner display by gauge() for displays over 4 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
GabyGold67 committed Nov 8, 2023
1 parent 38f2dea commit dfc0617
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 59 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FourBitLedDigitalTube",
"version": "2.0.0",
"version": "2.0.2",

"description": "7 segment 1 to 8 digits LED display easy to use and powerful library for modules based on two 74HC595 (or similar) shift registers chips. Developed for the cheap and popular '4-bit Led Digital Tube Module' (and for all the custom made displays as: GIANTS COUNTERS, TIMERS, PRICING DISPLAYS, etc.) based on two 74HC595 (or similar) shift registers, the main focus was set on: ease of use, flexibility and basic prevention of 'misrepresentation' errors.",
"keywords": "7 Segment, SevenSeg, 4 digits, 8 digits, LED, display, print, blink, gauge, floating point, negative, shift register, counter, tally counter, click counter",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=FourBitLedDigitalTube
version=2.0.0
version=2.0.2
author=Gabriel D. Goldman <[email protected]>
maintainer=Gabriel D. Goldman <[email protected]>
sentence=7 segment 4 digits LED display (and since v2.0.0 from 1 to 8 digits) easy to use and powerful library for modules based on two 74HC595 (or similar) shift registers chips
Expand Down
113 changes: 56 additions & 57 deletions src/FourBitLedDigitalTube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ uint8_t TM74HC595LedTube::_dspPtrArrLngth = 10;
TM74HC595LedTube** TM74HC595LedTube::_instancesLstPtr = nullptr;
bool TM74HC595LedTube::_intRfrshSrvcStrtd = false;

void TM74HC595LedTube::intRefresh(){
//ISR called by Timer1 to keep the display lit by calling each display's fastRefresh() method
for(uint8_t i {0}; i < _dspPtrArrLngth; i++){
if (*(_instancesLstPtr + i) != nullptr)
(*(_instancesLstPtr + i)) -> fastRefresh();
}

return;
}

TM74HC595LedTube::TM74HC595LedTube(uint8_t sclk, uint8_t rclk, uint8_t dio, bool commAnode, const uint8_t dspDigits)
:_sclk{sclk}, _rclk{rclk}, _dio{dio}, _commAnode{commAnode}, _dspDigits{dspDigits}, _digitPtr{new uint8_t (dspDigits)}, _blinkMaskPtr{new bool (dspDigits)}
{
Expand Down Expand Up @@ -69,8 +59,7 @@ bool TM74HC595LedTube::begin()
bool result {false};
int frstFreeSlot{-1};

//Verify if the timer interrupt service was started by checking if there are displays added to the pointers vector
if (!_intRfrshSrvcStrtd){
if (!_intRfrshSrvcStrtd){ //Verify if the timer interrupt service was started
//Initialize the Interrupt timer
Timer1.attachInterrupt(intRefresh);
Timer1.initialize(2000);
Expand Down Expand Up @@ -113,10 +102,10 @@ bool TM74HC595LedTube::blink(){
bool result {false};

if (!_blinking){
_blinkTimer = 0;
_blinkShowOn = false;
_blinking = true;
result = true;
_blinkTimer = 0;
_blinkShowOn = false;
_blinking = true;
result = true;
}

return result;
Expand Down Expand Up @@ -254,8 +243,8 @@ bool TM74HC595LedTube::gauge(const int &level, char label){
bool displayable{true};
String readOut{""};

clear(); // Ensures a clean display in case it's not displayable, and also trailing spaces if _dspDigits > 4
if (((level < 0) || (level > 3)) ||(_dspDigits < 4)) {
clear();
displayable = false;
}
else {
Expand Down Expand Up @@ -325,6 +314,16 @@ unsigned long TM74HC595LedTube::getMinBlinkRate(){
return _minBlinkRate;
}

void TM74HC595LedTube::intRefresh(){
//ISR called by Timer1 to keep the display lit by calling each display's fastRefresh() method
for(uint8_t i {0}; i < _dspPtrArrLngth; i++){
if (*(_instancesLstPtr + i) != nullptr)
(*(_instancesLstPtr + i)) -> fastRefresh();
}

return;
}

bool TM74HC595LedTube::isBlinking(){

return _blinking;
Expand Down Expand Up @@ -379,10 +378,10 @@ bool TM74HC595LedTube::print(String text){
if (text.charAt(i) != '.')
tempText += text.charAt(i);
else{
if (i == 0 || text.charAt(i-1) == '.')
if (i == 0 || text.charAt(i - 1) == '.')
tempText += " ";
if(tempText.length()<=4)
tempDpData[3-(tempText.length()-1)] = 0x7F;
if(tempText.length() <= _dspDigits)
tempDpData[(_dspDigits - 1) - (tempText.length() - 1)] = 0x7F;
}
}
text = tempText;
Expand Down Expand Up @@ -750,6 +749,16 @@ ClickCounter::~ClickCounter(){
//Class destructor
}

bool ClickCounter::blink(){

return TM74HC595LedTube::blink();
}

bool ClickCounter::blink(const unsigned long &onRate, const unsigned long &offRate){

return TM74HC595LedTube::blink(onRate, offRate);
}

void ClickCounter::clear(){

return TM74HC595LedTube::clear();
Expand All @@ -767,6 +776,18 @@ bool ClickCounter::countBegin(int startVal){
return result;
}

bool ClickCounter::countDown(int qty){
bool result {false};
qty = abs(qty);

if((_count - qty) >= _dspValMin){
_count -= qty;
result = updDisplay();
}

return result;
}

bool ClickCounter::countReset(){

return countRestart(_beginStartVal);
Expand All @@ -788,30 +809,6 @@ bool ClickCounter::countStop(){
return TM74HC595LedTube::stop();
}

bool ClickCounter::countUp(int qty){
bool result {false};
qty = abs(qty);

if((_count + qty) <= _dspValMax){
_count += qty;
result = updDisplay();
}

return result;
}

bool ClickCounter::countDown(int qty){
bool result {false};
qty = abs(qty);

if((_count - qty) >= _dspValMin){
_count -= qty;
result = updDisplay();
}

return result;
}

bool ClickCounter::countToZero(int qty){
bool result {false};

Expand All @@ -823,9 +820,16 @@ bool ClickCounter::countToZero(int qty){
return result;
}

bool ClickCounter::updDisplay(){
bool ClickCounter::countUp(int qty){
bool result {false};
qty = abs(qty);

return print(_count, _countRgthAlgn, _countZeroPad);
if((_count + qty) <= _dspValMax){
_count += qty;
result = updDisplay();
}

return result;
}

int ClickCounter::getCount(){
Expand All @@ -838,22 +842,17 @@ int ClickCounter::getStartVal(){
return _beginStartVal;
}

bool ClickCounter::setBlinkRate(const unsigned long &newOnRate, const unsigned long &newOffRate){

return TM74HC595LedTube::setBlinkRate(newOnRate, newOffRate);
}

bool ClickCounter::blink(){
bool ClickCounter::noBlink(){

return TM74HC595LedTube::blink();
return TM74HC595LedTube::noBlink();
}

bool ClickCounter::blink(const unsigned long &onRate, const unsigned long &offRate){
bool ClickCounter::setBlinkRate(const unsigned long &newOnRate, const unsigned long &newOffRate){

return TM74HC595LedTube::blink(onRate, offRate);
return TM74HC595LedTube::setBlinkRate(newOnRate, newOffRate);
}

bool ClickCounter::noBlink(){
bool ClickCounter::updDisplay(){

return TM74HC595LedTube::noBlink();
return print(_count, _countRgthAlgn, _countZeroPad);
}

0 comments on commit dfc0617

Please sign in to comment.