from machine import Pin
import time
#For shift register 1
DS_PIN_1 = 10 # Replace with the GPIO pin number connected to DS (data)
SHCP_PIN_1 = 11 # Replace with the GPIO pin number connected to SHCP (clock)
STCP_PIN_1 = 12 # Replace with the GPIO pin number connected to STCP (latch)
#For shift register 2
DS_PIN_2 = 0 # Replace with the GPIO pin number connected to DS (data)
SHCP_PIN_2 = 1 # Replace with the GPIO pin number connected to SHCP (clock)
STCP_PIN_2 = 2 # Replace with the GPIO pin number connected to STCP (latch)
NUM_DISPLAYS = 2
# Define 7-segment display patterns (common cathode)
SEGMENT_PATTERNS = {
0: 0b00111111,
1: 0b00000110,
2: 0b01011011,
3: 0b01001111,
4: 0b01100110,
5: 0b01101101,
6: 0b01111101,
7: 0b00000111,
8: 0b01111111,
9: 0b01101111,
# Add more patterns if necessary
}
# Initialize pins for the first shift register
ds_pin_1 = Pin(DS_PIN_1, Pin.OUT)
shcp_pin_1 = Pin(SHCP_PIN_1, Pin.OUT)
stcp_pin_1 = Pin(STCP_PIN_1, Pin.OUT)
# Initialize pins for the second shift register
ds_pin_2 = Pin(DS_PIN_2, Pin.OUT)
shcp_pin_2 = Pin(SHCP_PIN_2, Pin.OUT)
stcp_pin_2 = Pin(STCP_PIN_2, Pin.OUT)
#Function to shift data to the shift register
def shift_out(data):
for i in range(7, -1, -1):
ds_pin_1.value((data >> i) & 1)
shcp_pin_1.value(1)
shcp_pin_1.value(0)
#Function to update the displays
def update_displays(data):
stcp_pin_1.value(0)
shift_out(data)
stcp_pin_1.value(1)
try:
while True:
for number in range(10):
for display in range(NUM_DISPLAYS):
update_displays(SEGMENT_PATTERNS[number])
time.sleep(1) # Adjust the delay as needed
finally:
# Cleanup GPIO pins for the first shift register
ds_pin_1.deinit()
shcp_pin_1.deinit()
stcp_pin_1.deinit()
# Cleanup GPIO pins for the second shift register
ds_pin_2.deinit()
shcp_pin_2.deinit()
stcp_pin_2.deinit()