import machine
import utime
# Define the GPIO pins for each segment on the seven-segment display
segments = [2, 3, 4, 5, 6, 8, 7, 0]
# Define the segment patterns for numbers 0-9 and characters a-d
segment_patterns = {
'0': [0, 0, 0, 0, 0, 0, 1, 1],
'1': [1, 0, 0, 1, 1, 1, 1, 1],
'2': [0, 0, 1, 0, 0, 1, 0, 1],
'3': [0, 0, 0, 0, 1, 1, 0, 1],
'4': [1, 0, 0, 1, 1, 0, 0, 1],
'5': [0, 1, 0, 0, 1, 0, 0, 1],
'6': [0, 1, 0, 0, 0, 0, 0, 1],
'7': [0, 0, 0, 1, 1, 1, 1, 1],
'8': [0, 0, 0, 0, 0, 0, 0, 1],
'9': [0, 0, 0, 1, 1, 0, 0, 1],
'a': [0, 0, 0, 1, 0, 0, 0, 1],
'b': [1, 1, 0, 0, 0, 0, 0, 1],
'c': [0, 1, 1, 0, 0, 0, 1, 1],
'd': [1, 0, 0, 0, 0, 1, 0, 1]
}
# Initialize the GPIO pins as outputs
for pin in segments:
machine.Pin(pin, machine.Pin.OUT)
# Function to display a character on the seven-segment display
def display_character(char):
if char in segment_patterns:
pattern = segment_patterns[char]
for i, segment_pin in enumerate(segments):
machine.Pin(segment_pin, machine.Pin.OUT).value(pattern[i])
# Test the display by showing all characters and numbers
characters_to_display = "0123456789abcd"
while True:
for char in characters_to_display:
display_character(char)
utime.sleep(1)