Skip to content

Commit f71bdde

Browse files
committed
Added brightness control into the library.
By setting a frame size of about 3000us, the library now varies the amount of time the display is on and off. This means you only need to call .DisplayString over and over again.
1 parent be3c466 commit f71bdde

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

SevSeg/Example/SevSeg_Counter/SevSeg_Counter.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
7-23-2012
3-
Spark Fun Electronics
3+
Spark Fun Electronics
44
Nathan Seidle
55
66
This code is originally based Dean Reading's Library deanreading@hotmail.com

SevSeg/SevSeg.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
Any number between -999 and 9999 can be displayed.
5555
To move the decimal place one digit to the left, use '1' as the second
5656
argument. For example, if you wanted to display '3.141' you would call
57-
myDisplay.DisplayNumber(3141, 1);
57+
myDisplay.DisplayString("3141", 1, 250);
58+
The last argument (250) is the amount of time the display will be on in microseconds.
59+
Used in conjunction with
5860
5961
*/
6062

@@ -144,7 +146,8 @@ void SevSeg::Begin(boolean mode_in, byte numOfDigits,
144146
//Given a string such as "-A32", we display -A32
145147
//Each digit is displayed for ~2000us, and cycles through the 4 digits
146148
//After running through the 4 numbers, the display is turned off
147-
void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
149+
//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){
148151

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

@@ -183,8 +186,9 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
183186

184187
//Service the decimal point
185188
if(DecPlace == digit) digitalWrite(segmentDP, SegOn);
186-
187-
delayMicroseconds(2000); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
189+
190+
delayMicroseconds(brightnessLevel + 1); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
191+
//The + 1 is a bit of a hack but it removes the possible zero display (0 causes display to become bright and flickery)
188192
//If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
189193

190194
//Turn off all segments
@@ -215,6 +219,10 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
215219

216220
//This only currently works for 4 digits
217221
}
222+
223+
// 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
225+
218226
}
219227

220228
}

SevSeg/SevSeg.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515

1616
#define BLANK 16 //Special character that turns off all segments (we chose 16 as it is the first spot that has this)
1717

18+
// framePeriod controls the length of time between display refreshes
19+
// It's also closely linked to the brightness setting
20+
#define FRAMEPERIOD 3000
21+
//Total amount of time (in microseconds) for the display frame. 1,000us is roughly 1000Hz update rate
22+
//A framePeriod of:
23+
//5000 is flickery
24+
//3000 has good low brightness vs full brightness
25+
//2000 works well
26+
//500 seems like the low brightness is pretty bright, not great
27+
28+
1829
//This is the combined array that contains all the segment configurations for many different characters and symbols
1930
const unsigned char characterArray[128][7] = {
2031
// A B C D E F G Segments
@@ -155,7 +166,7 @@ class SevSeg {
155166
SevSeg();
156167

157168
//Public Functions
158-
void DisplayString(char*, byte);
169+
void DisplayString(char*, byte, unsigned int);
159170
// void NewNumber(int number_in, byte DecPlace_in);
160171
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);
161172

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