from machine import Pin, ADC
import time
# Define GPIO pin numbers for seg1 and seg2
seg1_pins = [25, 32, 33, 26, 27, 12, 14] # Adjust pin numbers as needed
seg2_pins = [2, 0, 4, 17, 5, 19, 18] # Adjust pin numbers as needed
# Initialize seg1 and seg2 Pin objects
seg1 = [Pin(pin, Pin.OUT) for pin in seg1_pins]
seg2 = [Pin(pin, Pin.OUT) for pin in seg2_pins]
# Define the mapping for each digit (0-9)
digits = [
[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],
[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 display a digit on the 7-segment display
def display_digit(digit, segment_pins):
for pin, state in zip(segment_pins, digits[digit]):
pin.value(state)
# Function to read potentiometer value and map it to countdown time
def read_pot_value():
pot_value = adc.read() # Read potentiometer value
print (int(pot_value * 59 / 1023))
return int(pot_value * 59 / 1023)
# Initialize ADC for reading potentiometer value
adc = ADC(Pin(15))
adc.atten(ADC.ATTN_11DB)
# Initialize countdown time
countdown_time = 0
# Main loop
while True:
# Read potentiometer value and map it to countdown time
countdown_time = read_pot_value()
# Display tens digit on seg1 and ones digit on seg2
display_digit(countdown_time // 10, seg1)
print (countdown_time // 10, seg1)
display_digit(countdown_time % 10, seg2)
print (countdown_time % 10, seg2)
time.sleep(1) # Update display every 1 second