Skip to content

Commit 878f599

Browse files
committed
Added a SetBrightness command. Now uses percentage 0 to 100.
Error checking and correct mapping of the delay values are now calculated for the user in the SetBrightness command. User supplies value 0 to 100 percent and SetBrightness maps to correct delay value.
1 parent f71bdde commit 878f599

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

SevSeg/SevSeg.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,25 @@ void SevSeg::Begin(boolean mode_in, byte numOfDigits,
141141
}
142142
}
143143

144+
//Set the display brightness
145+
/*******************************************************************************************/
146+
//Given a value between 0 and 100 (0% and 100%), set the brightness variable on the display
147+
//We need to error check and map the incoming value
148+
void SevSeg::SetBrightness(byte percentBright)
149+
{
150+
//Error check and scale brightnessLevel
151+
if(percentBright > 100) percentBright = 100;
152+
brightnessDelay = map(percentBright, 0, 100, 0, FRAMEPERIOD); //map brightnessDelay to 0 to the max which is framePeriod
153+
}
154+
155+
144156
//Refresh Display
145157
/*******************************************************************************************/
146158
//Given a string such as "-A32", we display -A32
147159
//Each digit is displayed for ~2000us, and cycles through the 4 digits
148160
//After running through the 4 numbers, the display is turned off
149161
//Will turn the display on for a given amount of time - this helps control brightness
150-
void SevSeg::DisplayString(char* toDisplay, byte DecPlace, unsigned int brightnessLevel){
162+
void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
151163

152164
//For the purpose of this code, digit = 1 is the left most digit, digit = 4 is the right most digit
153165

@@ -187,7 +199,7 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace, unsigned int brightne
187199
//Service the decimal point
188200
if(DecPlace == digit) digitalWrite(segmentDP, SegOn);
189201

190-
delayMicroseconds(brightnessLevel + 1); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
202+
delayMicroseconds(brightnessDelay + 1); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
191203
//The + 1 is a bit of a hack but it removes the possible zero display (0 causes display to become bright and flickery)
192204
//If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
193205

@@ -221,7 +233,7 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace, unsigned int brightne
221233
}
222234

223235
// The display is on for microSeconds(brightnessLevel + 1), now turn off for the remainder of the framePeriod
224-
delayMicroseconds(FRAMEPERIOD - brightnessLevel + 1); //the +1 is a hack so that we can never have a delayMicroseconds(0), causes display to flicker
236+
delayMicroseconds(FRAMEPERIOD - brightnessDelay + 1); //the +1 is a hack so that we can never have a delayMicroseconds(0), causes display to flicker
225237

226238
}
227239

SevSeg/SevSeg.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ class SevSeg {
166166
SevSeg();
167167

168168
//Public Functions
169-
void DisplayString(char*, byte, unsigned int);
169+
void DisplayString(char*, byte);
170170
// void NewNumber(int number_in, byte DecPlace_in);
171171
void Begin(boolean mode_in, byte numOfDigits, byte digit1, byte digit2, byte digit3, byte digit4, byte segment1, byte segment2, byte segment3, byte segment4, byte segment5, byte segment6, byte segment7, byte segmentDP);
172+
void SetBrightness(byte percentBright);
172173

173174
//Public Variables
174175

@@ -184,6 +185,8 @@ class SevSeg {
184185
byte segmentA, segmentB, segmentC, segmentD, segmentE, segmentF, segmentG, segmentDP;
185186

186187
byte numberOfDigits;
188+
189+
unsigned int brightnessDelay;
187190

188191
byte DigitPins[4];
189192
byte SegmentPins[8];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy