1
1
/*
2
- Originally written by Dean Reading deanreading@hotmail.com, 2012
2
+ This library allows an Arduino to easily display numbers and characters on a 4 digit 7-segment
3
+ display without a separate 7-segment display controller.
3
4
4
- Version 2.0 updated by Nathan Seidle, 2012: Now works for any digital pin arrangement, common anode and common cathode displays.
5
- Please see https://github.com/nseidle for support and to send in suggestions
6
-
7
- This library allows an Arduino to easily display numbers in decimal format on
8
- a 4 digit 7-segment display without a separate 7-segment display controller.
9
-
10
- Hardware:
11
- 4 digit 7 segment displays use 12 digital pins.
12
-
13
- There are:
14
- 4 common pins; 1 for each digit. These will be cathodes (negative pins) for
15
- common cathode displays, or anodes (positive pins) for common anode displays.
16
- I refer to these as digit pins. 8 pins for the individual segments (seven segments plus the decimal point).
17
- I refer to these as segment pins.
18
-
19
- Connect the four digit pins with four limiting resistors in series to any digital or analog pins.
20
- Connect the eight cathodes to any digital or analog pins.
5
+ If you have feature suggestions or need support please use the github support page: https://github.com/sparkfun/SevSeg
6
+
7
+ Original Library by Dean Reading (deanreading@hotmail.com: http://arduino.cc/playground/Main/SevenSegmentLibrary), 2012
8
+ Improvements by Nathan Seidle, 2012
9
+
10
+ Now works for any digital pin arrangement, common anode and common cathode displays.
11
+ Added character support including letters A-F and many symbols.
12
+
13
+ Hardware Setup: 4 digit 7 segment displays use 12 digital pins. You may need more pins if your display has colons or
14
+ apostrophes.
15
+
16
+ There are 4 digit pins and 8 segment pins. Digit pins are connected to the cathodes for common cathode displays, or anodes
17
+ for common anode displays. 8 pins control the individual segments (seven segments plus the decimal point).
18
+
19
+ Connect the four digit pins with four limiting resistors in series to any digital or analog pins. Connect the eight segment
20
+ pins to any digital or analog pins (no limiting resistors needed). See the SevSeg example for more connection information.
21
21
22
- I have a cheap one from China, and the pins of the display are in the following order:
23
- Top Row
24
- 1,a,f,2,3,b
25
- Bottom Row
26
- e,d,dp,c,g,4
27
- Where the digit pins are 1-4 and the segment pins are a-g + dp
22
+ SparkFun has a large, 1" 7-segment display that has four digits.
23
+ https://www.sparkfun.com/products/11408
24
+ Looking at the display like this: 8.8.8.8. pin 1 is on the lower row, starting from the left.
25
+ Pin 12 is the top row, upper left pin.
28
26
27
+ Pinout:
28
+ 1: Segment E
29
+ 2: Segment D
30
+ 3: Segment DP
31
+ 4: Segment C
32
+ 5: Segment G
33
+ 6: Digit 4
34
+ 7: Segment B
35
+ 8: Digit 3
36
+ 9: Digit 2
37
+ 10: Segment F
38
+ 11: Segment A
39
+ 12: Digit 1
40
+
41
+
29
42
Software:
30
43
Call SevSeg.Begin in setup.
31
44
The first argument (boolean) tells whether the display is common cathode (0) or common
37
50
38
51
In summary, Begin(type, digit pins 1-4, segment pins a-g, dp)
39
52
40
- The calling program must run the DisplayNumber () function repeatedly to get the number displayed.
53
+ The calling program must run the DisplayString () function repeatedly to get the number displayed.
41
54
Any number between -999 and 9999 can be displayed.
42
55
To move the decimal place one digit to the left, use '1' as the second
43
- argument in NewNum . For example, if you wanted to display '3.141' you would
44
- call myDisplay.DisplayNumber(3141,3 );
56
+ argument. For example, if you wanted to display '3.141' you would call
57
+ myDisplay.DisplayNumber(3141, 1 );
45
58
46
59
*/
47
60
@@ -107,7 +120,6 @@ void SevSeg::Begin(boolean mode_in, byte numOfDigits,
107
120
SegmentPins[6 ] = segmentG;
108
121
SegmentPins[7 ] = segmentDP;
109
122
110
-
111
123
// Set Pin Modes as outputs
112
124
for (byte digit = 0 ; digit < numberOfDigits ; digit++) {
113
125
pinMode (DigitPins[digit], OUTPUT);
@@ -156,6 +168,8 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
156
168
// This only currently works for 4 digits
157
169
}
158
170
171
+ // Here we access the array of segments
172
+ // This could be cleaned up a bit but it works
159
173
// displayCharacter(toDisplay[digit-1]); //Now display this digit
160
174
// displayArray (defined in SevSeg.h) decides which segments are turned on for each number or symbol
161
175
char characterToDisplay = toDisplay[digit-1 ];
@@ -204,52 +218,3 @@ void SevSeg::DisplayString(char* toDisplay, byte DecPlace){
204
218
}
205
219
206
220
}
207
-
208
- // Display a number, letter, or symbol
209
- /* ******************************************************************************************/
210
- // Given a number or letter, light up the right segments on a given position
211
- // We assume the caller has the digit's Anode/Cathode turned on
212
- void SevSeg::displayCharacter (byte characterToDisplay) {
213
-
214
- // Segments in the display are named like this:
215
- // - A
216
- // F / / B
217
- // - G
218
- // E / / C
219
- // - D
220
-
221
- // displayArray (defined in SevSeg.h) decides which segments are turned on for each number or symbol
222
- if (characterArray[characterToDisplay][0 ]) digitalWrite (segmentA, SegOn);
223
- if (characterArray[characterToDisplay][1 ]) digitalWrite (segmentB, SegOn);
224
- if (characterArray[characterToDisplay][2 ]) digitalWrite (segmentC, SegOn);
225
- if (characterArray[characterToDisplay][3 ]) digitalWrite (segmentD, SegOn);
226
- if (characterArray[characterToDisplay][4 ]) digitalWrite (segmentE, SegOn);
227
- if (characterArray[characterToDisplay][5 ]) digitalWrite (segmentF, SegOn);
228
- if (characterArray[characterToDisplay][6 ]) digitalWrite (segmentG, SegOn);
229
-
230
- /*
231
- case DP:
232
- digitalWrite(segmentDP, SegOn);
233
- break;
234
- */
235
-
236
- /*
237
- default:
238
- lights[digit][0] = 0;
239
- lights[digit][1] = 0;
240
- lights[digit][2] = 1;
241
- lights[digit][3] = 1;
242
- lights[digit][4] = 1;
243
- lights[digit][5] = 0;
244
- lights[digit][6] = 1;
245
- break;
246
- */
247
-
248
- // Set the decimal place lights
249
- /* if (numberOfDigits - 1 - digit == DecPlace){
250
- lights[digit][7] = 1;
251
- }
252
- else {
253
- lights[digit][7] = 0;
254
- }*/
255
- }
0 commit comments