Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
5.2 - Number Display¶
LED Segment Display can be seen everywhere in life. For example, on an air conditioner, it can be used to display temperature; on a traffic indicator, it can be used to display a timer.
The LED Segment Display is essentially a device packaged by 8 LEDs, of which 7 strip-shaped LEDs form an “8” shape, and there is a slightly smaller dotted LED as a decimal point. These LEDs are marked as a, b, c, d, e, f, g, and dp. They have their own anode pins and share cathodes. Their pin locations are shown in the figure below.
This means that it needs to be controlled by 8 digital signals at the same time to fully work and the 74HC595 can do this.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
PURCHASE LINK |
---|---|---|
Kepler Kit |
450+ |
You can also buy them separately from the links below.
SN |
COMPONENT INTRODUCTION |
QUANTITY |
PURCHASE LINK |
---|---|---|---|
1 |
1 |
||
2 |
Micro USB Cable |
1 |
|
3 |
1 |
||
4 |
Several |
||
5 |
1(220Ω) |
||
6 |
1 |
||
7 |
1 |
Schematic
Wiring
LED Segment Display |
|
---|---|
Q0 |
a |
Q1 |
b |
Q2 |
c |
Q3 |
d |
Q4 |
e |
Q5 |
f |
Q6 |
g |
Q7 |
dp |
Code
Note
You can open the file
5.2_number_display.ino
under the path ofkepler-kit-main/arduino/5.2_number_display
.Or copy this code into Arduino IDE.
Don’t forget to select the board(Raspberry Pi Pico) and the correct port before clicking the Upload button.
When the program is running, you will be able to see the LED Segment Display display 0~9 in sequence.
How it works?
shiftOut()
will make 74HC595 output 8 digital signals.
It outputs the last bit of the binary number to Q0, and the output of the first bit to Q7. In other words, writing the binary number “00000001” will make Q0 output high level and Q1~Q7 output low level.
Suppose that the 7-segment Display display the number “1”, we need to write a high level for b, c, and write a low level for a, d, e, f, g, and dg. That is, the binary number “00000110” needs to be written. For readability, we will use hexadecimal notation as “0x06”.
Similarly, we can also make the LED Segment Display display other numbers in the same way. The following table shows the codes corresponding to these numbers.
Numbers |
Binary Code |
Hex Code |
---|---|---|
0 |
00111111 |
0x3f |
1 |
00000110 |
0x06 |
2 |
01011011 |
0x5b |
3 |
01001111 |
0x4f |
4 |
01100110 |
0x66 |
5 |
01101101 |
0x6d |
6 |
01111101 |
0x7d |
7 |
00000111 |
0x07 |
8 |
01111111 |
0x7f |
9 |
01101111 |
0x6f |
Write these codes into shiftOut()
to make the LED Segment Display display the corresponding numbers.