# MCA Lab Assessment 2
from machine import Pin
import time
# Set GPIO pins for 74HC595 Shift Register
dataPin = Pin(18, Pin.OUT) # Serial Data Input (DS Pin 14)
latchPin = Pin(19, Pin.OUT) # Storage Register Clock (STCP Pin 12)
clockPin = Pin(20, Pin.OUT) # Shift Register Clock (SHCP Pin 11)
# Set GPIO pins for rows of dot matrix with output(high)
rowPin0 = Pin(0, Pin.OUT, value = 1)
rowPin2 = Pin(2, Pin.OUT, value = 1)
Pat1 = 0x0F # Patterns
Pat2 = 0x6C
# Shifts 8 bit data into 74HC595 shift register.
def hc595_in(dat):
latchPin.low()
for i in range(8):
clockPin.low()
dataPin.value((dat >> (7 - i)) & 1) # Output data bit by bit
clockPin.high()
time.sleep_us(1) # Short delay to ensure proper timing
latchPin.high()
while True:
hc595_in(Pat1) # Send the 8-bit data to the columns
rowPin0.low() # Activate row
time.sleep_ms(1000) # Delay
rowPin0.high() # Deactivate row
hc595_in(Pat2)
rowPin2.low()
time.sleep_ms(1000)
rowPin2.high()