@@ -141,13 +141,25 @@ void SevSeg::Begin(boolean mode_in, byte numOfDigits,
141
141
}
142
142
}
143
143
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
+
144
156
// Refresh Display
145
157
/* ******************************************************************************************/
146
158
// Given a string such as "-A32", we display -A32
147
159
// Each digit is displayed for ~2000us, and cycles through the 4 digits
148
160
// After running through the 4 numbers, the display is turned off
149
161
// 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){
151
163
152
164
// For the purpose of this code, digit = 1 is the left most digit, digit = 4 is the right most digit
153
165
@@ -187,7 +199,7 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace, unsigned int brightne
187
199
// Service the decimal point
188
200
if (DecPlace == digit) digitalWrite (segmentDP, SegOn);
189
201
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)
191
203
// The + 1 is a bit of a hack but it removes the possible zero display (0 causes display to become bright and flickery)
192
204
// If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
193
205
@@ -221,7 +233,7 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace, unsigned int brightne
221
233
}
222
234
223
235
// 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
225
237
226
238
}
227
239
0 commit comments