from machine import Pin
import utime
# Setup Pins
sdi = Pin(13, Pin.OUT)
rclk = Pin(14, Pin.OUT)
srclk = Pin(15, Pin.OUT)
# Segment patterns for 0-9 (Common Cathode)
digits = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
def shift_out_16(tens_val, ones_val):
"""Pushes 16 bits to the daisy-chained registers."""
rclk.low()
# We send the 'ones' first so it ends up in the second register (Display 2)
# The 'tens' follows it and stays in the first register (Display 1)
for byte in [ones_val, tens_val]:
for i in range(8):
srclk.low()
bit = (byte >> (7 - i)) & 0x01
sdi.value(bit)
srclk.high()
rclk.high()
# Main Counter Loop
while True:
for count in range(100): # Counts from 0 to 99
tens = count // 10
ones = count % 10
# Get the segment patterns and update
shift_out_16(digits[tens], digits[ones])
# Wait half a second before the next number
utime.sleep(0.5)