# imports
from machine import Pin
from time import sleep
import math
#######################################
# Define segment pins (shared for both digits: a-g)
SEVEN_SEGMENT_START_PIN = 0
DISPLAY_COUNT = 1
DECIMAL_PRECISION = 1
# Define digit selector pins (to switch between the two digits)
digit_pins = [
Pin(7, Pin.OUT), # Digit 1 (left)
Pin(8, Pin.OUT), # Digit 2 (right)
]
# Button input pin
button = Pin(22, Pin.IN, Pin.PULL_DOWN)
# Number to segment mapping (0–9)
number_map = [
[1, 1, 1, 1, 1, 1, 0], # 0
[0, 1, 1, 0, 0, 0, 0], # 1
[1, 1, 0, 1, 1, 0, 1], # 2
[1, 1, 1, 1, 0, 0, 1], # 3
[0, 1, 1, 0, 0, 1, 1], # 4
[1, 0, 1, 1, 0, 1, 1], # 5
[1, 0, 1, 1, 1, 1, 1], # 6
[1, 1, 1, 0, 0, 0, 0], # 7
[1, 1, 1, 1, 1, 1, 1], # 8
[1, 1, 1, 1, 0, 1, 1] # 9
]
# Function to display a digit on a specific display position
def display_digit(digit_index, number):
segments_state = number_map[number]
# Turn off both digits first
for i in range(2):
digit_pins[i].value(1) # Assuming common cathode (active LOW)
# Set the segments for the digit
for i in range(7):
segments[i].value(segments_state[i])
# Turn on the desired digit
digit_pins[digit_index].value(0) # Enable the selected digit
# Initialize counter
counter = 0
# Main loop
while True:
tens = (counter // 10) % 10
ones = counter % 10
# Multiplexing both digits
display_digit(0, tens)
sleep(0.005)
display_digit(1, ones)
sleep(0.005)
# Button press handling
if button.value(): counter = (counter + 1) % 100
else:
sleep(0.05)
# Define SELECTOR pins
Button = machine.Pin(22, machine.Pin.IN)
segments = [
machine.Pin(0, machine.Pin.OUT),
machine.Pin(1, machine.Pin.OUT),
machine.Pin(2, machine.Pin.OUT),
machine.Pin(3, machine.Pin.OUT),
machine.Pin(4, machine.Pin.OUT),
machine.Pin(5, machine.Pin.OUT),
machine.Pin(6, machine.Pin.OUT),
machine.Pin(7, machine.Pin.OUT),
machine.Pin(8, machine.Pin.OUT),
machine.Pin(9, machine.Pin.OUT),
machine.Pin(10, machine.Pin.OUT),
machine.Pin(11, machine.Pin.OUT),
]
number_map = [
[1, 1, 1, 1, 1, 1, 0], # 0
[0, 1, 1, 0, 0, 0, 0], # 1
[1, 1, 0, 1, 1, 0, 1], # 2
[1, 1, 1, 1, 0, 0, 1], # 3
[0, 1, 1, 0, 0, 1, 1], # 4
[1, 0, 1, 1, 0, 1, 1], # 5
[1, 0, 1, 1, 1, 1, 1], # 6
[1, 1, 1, 0, 0, 0, 0], # 7
[1, 1, 1, 1, 1, 1, 1], # 8
[1, 1, 1, 1, 0, 1, 1] # 9
]
# Pin and constant definitions
#######################################
def display_number(number):
segments_values = number_map[number]
for i in range(len(segments)):
segments[i].value(segments_values[i])
while True:
for number in range(10):
display_number(number)
utime.sleep_ms(1000)
#######################################
# Global variables
#######################################
display_value = 0
#######################################
# Function definitions
#######################################
# Function to read the ADC pin and
# to convert the digital value to a voltage level in the 0-3.3V range
# This function updates the value of the display_value global variable
def read_analogue_voltage(pin): # We can use the pin parameter if needed
pass
# Function to disable timer that triggers scanning 7 segment displays
def disable_display_timer():
pass
# Function to enable timer that triggers scanning 7 segment displays
def enable_display_timer():
pass
# Function to handle scanning 7 segment displays
# Display the value stored in the display_value global variable
# on available 7-segment displays
def scan_display(timer_int):
pass
# Function display the given value on the display with the specified index
# dp_enable specifies if the decimal pooint should be on or off
def display_digit(digit_value, digit_index, dp_enable=False):
pass
# Function to test avaiable 7-segment displays
def display_value_test():
pass
# Function to setup GPIO/ADC pins, timers and interrupts
def setup():
pass
if __name__ == '__main__':
setup()
#display_value_test()