import machine
import time
import sys

A0 = machine.Pin(5, machine.Pin.OUT, value=0)
A1 = machine.Pin(18, machine.Pin.OUT, value=0)

RCK = machine.Pin(4, machine.Pin.OUT, value=0)
SCK = machine.Pin(2, machine.Pin.OUT, value=0)
SER = machine.Pin(15, machine.Pin.OUT, value=0)

spi = machine.SoftSPI(baudrate=100, polarity=0, phase=0, sck=SCK, mosi=SER, miso=machine.Pin(14))
spi.init()

def dsp(d):
    if(d == 0):
        A0.value(0)
        A1.value(0)
    elif(d == 1):
        A0.value(1)
        A1.value(0)
    elif(d == 2):
        A0.value(0)
        A1.value(1)
    elif(d == 3):
        A0.value(1)
        A1.value(1)

def latch():
    RCK.value(1)
    RCK.value(0)

try:
    while True:
        spi.write(b"\x01")
        latch()
        dsp(0)
        time.sleep_ms(500)

        spi.write(b"\x02")
        latch()
        dsp(1)
        time.sleep_ms(500)

        spi.write(b"\x04")
        latch()
        dsp(2)
        time.sleep_ms(500)

        spi.write(b"\x08")
        latch()
        dsp(3)
        time.sleep_ms(500)

except KeyboardInterrupt:
    spi.deinit()
    print("Program sonlandırıldı.\n")
74HC595