Skip to content

Commit 8a25f43

Browse files
committed
Changed setSegment to setSegmentsDigit
Also improved README
1 parent 919c425 commit 8a25f43

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ void setup() {
102102
If you wish to use more than 8 digits, increase MAXNUMDIGITS in SevSeg.h.
103103

104104

105+
### Refreshing the display
106+
107+
```c++
108+
sevseg.refreshDisplay();
109+
```
110+
111+
Your program must run the refreshDisplay() function repeatedly to display the number.
112+
**Warning: Any calls to delay() will interfere with the display.**
113+
Any delays introduced by other functions will produce undesirable effects on the display. If you need help getting away from delay() statements, I recommend the simple [Blink Without Delay][9] arduino example sketch.
114+
115+
To blank the display, call:
116+
117+
```c++
118+
sevseg.blank();
119+
```
120+
105121
### Setting a number
106122
#### Integer
107123
```c++
@@ -127,23 +143,19 @@ Note that:
127143
sevseg.setChars("abcd");
128144
```
129145

130-
Character arrays can be displayed - as accurately as possible on a seven segment display. See SevSeg.cpp digitCodeMap[] to notes on each character. Only alphanumeric characters, plus ' ', '-' and '.' are supported. The character array should be NULL terminated.
131-
132-
133-
### Refreshing the display
146+
Character arrays can be displayed - as accurately as possible on a seven segment display. See SevSeg.cpp digitCodeMap[] to notes on each character. Only alphanumeric characters, plus ' ', '-', '_', and '.' are supported. The character array should be NULL terminated.
134147

148+
### Custom display setting
135149
```c++
136-
sevseg.refreshDisplay();
150+
// Set the segments for every digit on the display
151+
uint8_t segs[4] = {0, 0x5B, 0x6D, 0x63};
152+
sevseg.setSegments(segs);
137153
```
138-
139-
Your program must run the refreshDisplay() function repeatedly to display the number. Note that any delays introduced by other functions will produce undesirable effects on the display.
140-
141-
To blank the display, call:
142-
143154
```c++
144-
sevseg.blank();
155+
// Set the segments for a single digit. Set digit 3 to 0x63.
156+
sevseg.setSegmentsDigit(3, 0x63);
145157
```
146-
158+
You can manipulate individual segments if needed. Each byte represents the display of a single digit, with each bit representing a single segment. The bits represent segments in the order .GFEDCBA. See SevSeg.cpp for more examples of these 'digitCodes'.
147159

148160
### Setting the brightness
149161

@@ -188,3 +200,4 @@ SOFTWARE.
188200
[6]: https://wokwi.com/arduino/libraries/SevSeg/SevSeg_Counter
189201
[7]: https://wokwi.com/arduino/libraries/SevSeg/stringWithPeriod
190202
[8]: https://wokwi.com/arduino/libraries/SevSeg/testWholeDisplay
203+
[9]: https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay

SevSeg.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static const int32_t powersOf16[] = {
4444
// digitCodeMap indicate which segments must be illuminated to display
4545
// each number.
4646
static const uint8_t digitCodeMap[] = {
47-
// GFEDCBA Segments 7-segment map:
47+
// GFEDCBA Segments 7-segment map:
4848
0b00111111, // 0 "0" AAA
4949
0b00000110, // 1 "1" F B
5050
0b01011011, // 2 "2" F B
@@ -433,11 +433,14 @@ void SevSeg::setSegments(const uint8_t segs[]) {
433433
}
434434
}
435435

436-
// setSegment
436+
// setSegmentsDigit
437437
/******************************************************************************/
438-
// Like setSegments above, only manipulates one segment
439-
void SevSeg::setSegment(const byte segNum, const byte segs) {
440-
digitCodes[segNum] = segs;
438+
// Like setSegments above, but only manipulates the segments for one digit
439+
// digitNum is 0-indexed.
440+
void SevSeg::setSegmentsDigit(const uint8_t digitNum, const uint8_t segs) {
441+
if (digitNum < numDigits) {
442+
digitCodes[digitNum] = segs;
443+
}
441444
}
442445

443446
// getSegments

SevSeg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SevSeg
4848

4949
void setSegments(const uint8_t segs[]);
5050
void getSegments(uint8_t segs[]);
51-
void setSegment(const byte segNum, const byte segs);
51+
void setSegmentsDigit(const uint8_t digitNum, const uint8_t segs);
5252
void setChars(const char str[]);
5353
void blank(void);
5454

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ refreshDisplay KEYWORD2
55
setBrightness KEYWORD2
66
getSegments KEYWORD2
77
setSegments KEYWORD2
8+
setSegmentsDigit KEYWORD2
89
setChars KEYWORD2
910
blank KEYWORD2
1011
COMMON_CATHODE LITERAL1

0 commit comments

Comments
 (0)