Skip to content

Commit

Permalink
Issue #151 - Brightness=0 completely switches display off (#150)
Browse files Browse the repository at this point in the history
fixes #151
  • Loading branch information
GioCC authored Feb 3, 2022
1 parent 6f36545 commit 58a8e0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions include/MFSegments.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class MFSegments
void setBrightness(byte module, byte value);

private:
LedControl _ledControl;
bool _initialized;
byte _moduleCount;
LedControl _ledControl;
byte _moduleCount;
};
#endif
20 changes: 12 additions & 8 deletions src/MF_Modules/MFSegments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

MFSegments::MFSegments()
{
_initialized = false;
_moduleCount = 0;
}

void MFSegments::display(byte module, char *string, byte points, byte mask, bool convertPoints)
{
if (!_initialized)
if (_moduleCount == 0)
return;

byte digit = 8;
byte pos = 0;
for (int i = 0; i != 8; i++)
Expand All @@ -28,18 +27,23 @@ void MFSegments::display(byte module, char *string, byte points, byte mask, bool

void MFSegments::setBrightness(byte module, byte value)
{
if (!_initialized)
if (_moduleCount == 0)
return;
if (module < _moduleCount)
{
_ledControl.setIntensity(module, value);
if(value)
{
_ledControl.setIntensity(module, value-1);
_ledControl.shutdown(module, false);
} else {
_ledControl.shutdown(module, true);
}
}
}

void MFSegments::attach(int dataPin, int csPin, int clkPin, byte moduleCount, byte brightness)
{
_ledControl.begin(dataPin, clkPin, csPin, moduleCount);
_initialized = true;
_moduleCount = moduleCount;
for (int i = 0; i != _moduleCount; ++i)
{
Expand All @@ -51,7 +55,7 @@ void MFSegments::attach(int dataPin, int csPin, int clkPin, byte moduleCount, by

void MFSegments::detach()
{
_initialized = false;
_moduleCount = 0;
}

void MFSegments::powerSavingMode(bool state)
Expand All @@ -64,7 +68,7 @@ void MFSegments::powerSavingMode(bool state)

void MFSegments::test()
{
if (!_initialized)
if (_moduleCount == 0)
return;
byte _delay = 10;
byte module = 0;
Expand Down

0 comments on commit 58a8e0d

Please sign in to comment.