import machine
import time
# Define the GPIO pins connected to the segments of the display
# Replace the pin numbers with the ones you're using
segments = [machine.Pin(14, machine.Pin.OUT), # A
machine.Pin(27, machine.Pin.OUT), # B
machine.Pin(26, machine.Pin.OUT), # C
machine.Pin(25, machine.Pin.OUT), # D
machine.Pin(33, machine.Pin.OUT), # E
machine.Pin(32, machine.Pin.OUT), # F
machine.Pin(15, machine.Pin.OUT)] # G
# Define the GPIO pins connected to the digits of the display
# Replace the pin numbers with the ones you're using
digits = [machine.Pin(13, machine.Pin.OUT), # D1
machine.Pin(12, machine.Pin.OUT)] # D2
# Define the mapping between digits and segments
# Each row represents a digit, and each column represents a segment (A to G)
# A value of 1 means the segment should be turned on for that digit, 0 means off
digit_to_segment = [[0,0,0,0,0,0,1],
[1,0,0,1,1,1,1],
[0,0,1,0,0,1,0],
[0,0,0,0,1,1,0],
[1,0,0,1,1,0,0],
[0,1,0,0,1,0,0],
[0,1,0,0,0,0,0],
[0,0,0,1,1,1,1],
[0,0,0,0,0,0,0],
[0,0,0,0,1,0,0]
]
# Function to turn on the segments for a given digit
def set_digit(digit):
for i in range(7):
segments[i].value(digit_to_segment[digit][i])
# Function to display a two-digit number on the display
def display_number(number):
# Separate the tens and ones digits
tens = number // 10
ones = number % 10
# Display the tens digit on the first digit of the display
digits[0].value(1)
digits[1].value(0)
set_digit(tens)
time.sleep(0.001)
digits[0].value(0)
# Display the ones digit on the second digit of the display
digits[0].value(0)
digits[1].value(1)
set_digit(ones)
time.sleep(0.001)
digits[1].value(0)
# Loop from 0 to 99 and display each number on the display
for i in range(100):
display_number(i)
time.sleep(1)