from machine import Pin
import time
# Define GPIO pins for 74595 IC
data_pin = Pin(14, Pin.OUT) # Serial Data Input (DS)
clock_pin = Pin(12, Pin.OUT) # Clock Input (SHCP)
latch_pin = Pin(13, Pin.OUT) # Latch Input (STCP)
# Function to shift out data to 74595 IC
def shift_out(data):
latch_pin.off() # Start shifting data
for i in range(8):
bit = (data >> i) & 0x01 # Get individual bit
data_pin.value(bit) # Set data pin to bit value
clock_pin.on() # Pulse clock pin
clock_pin.off()
latch_pin.on() # Latch data to outputs
# Example usage: Shift out binary pattern '10101010'
zero = 0xC0
one = 0xF9
two = 0xA4
three = 0b10110000
four = 0b10011001
five = 0b10010010
six = 0b10000010
seven = 0b11111000
eight = 0b10000000
nine = 0b10010000
masa = 0.5
while True:
shift_out(zero)
time.sleep(masa) # Delay for demonstration
shift_out(one)
time.sleep(masa) # Delay for demonstration
shift_out(two)
time.sleep(masa) # Delay for demonstration
shift_out(three)
time.sleep(masa) # Delay for demonstration
shift_out(four)
time.sleep(masa) # Delay for demonstration
shift_out(five)
time.sleep(masa) # Delay for demonstration
shift_out(six)
time.sleep(masa) # Delay for demonstration
shift_out(seven)
time.sleep(masa) # Delay for demonstration
shift_out(eight)
time.sleep(masa) # Delay for demonstration
shift_out(nine)
time.sleep(masa) # Delay for demonstration