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
while True:
shift_out(zero)
time.sleep(1) # Delay for demonstration
shift_out(one)
time.sleep(1) # Delay for demonstration
shift_out(two)
time.sleep(1) # Delay for demonstration