🙉 Tutorial 26 - 7 Segment Display
A 7-segment display is an electronic device that is used to display numeric information in a digital format. It consists of seven LED (Light Emitting Diode) segments arranged in a rectangular shape, with an eighth segment for displaying decimal points. Each of the seven segments can be lit up individually, allowing for the display of numbers 0 through 9, as well as some letters and symbols.
The 7-segment display is commonly used in digital clocks, calculators, and other electronic devices that require numeric displays. It can be interfaced with a microcontroller or other digital device, and controlled using simple digital signals.
There are two types of 7-segment displays: common anode and common cathode. In a common anode display, all the anodes of the LEDs are connected together and to a positive voltage source, while each of the cathodes is connected to a digital output pin. In a common cathode display, the cathodes of the LEDs are connected together and to a negative voltage source, while each of the anodes is connected to a digital output pin.
To display a number on the 7-segment display, the appropriate digital outputs are turned on or off, causing the corresponding segments to light up.
Overall, the 7-segment display is a versatile and widely-used display module that provides a simple and effective way to display numeric information in a digital format. Its ease of use and low power consumption make it a popular choice for hobbyists and professionals alike.
Components Needed
Component | Quantity |
---|---|
Raspberry Pi Pico W | 1 |
Micro USB Cable | 1 |
Breadboard | 1 |
Wires | Several |
Resistor | 1 - 220Ω |
7 Segment Display | 1 |
74HC595 | 1 |
Fritzing Diagram
Code
import machine
import time
SEGCODE = [0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f]
sdi = machine.Pin(0,machine.Pin.OUT)
rclk = machine.Pin(1,machine.Pin.OUT)
srclk = machine.Pin(2,machine.Pin.OUT)
def hc595_shift(dat):
rclk.low()
time.sleep_ms(5)
for bit in range(7, -1, -1):
srclk.low()
time.sleep_ms(5)
value = 1 & (dat >> bit)
sdi.value(value)
time.sleep_ms(5)
srclk.high()
time.sleep_ms(5)
time.sleep_ms(5)
rclk.high()
time.sleep_ms(5)
while True:
for num in range(10):
hc595_shift(SEGCODE[num])
time.sleep_ms(500)