# Import library untuk motor stepper
from machine import Pin
import time
# Konfigurasi pin output
pin1 = Pin(12, Pin.OUT)
pin2 = Pin(13, Pin.OUT)
pin3 = Pin(14, Pin.OUT)
pin4 = Pin(15, Pin.OUT)
# Fungsi untuk menggerakkan motor stepper ke arah tertentu
def gerak_stepper(langkah, arah):
for i in range(langkah):
if arah == 'CW':
pin1.value(1)
time.sleep_ms(5)
pin2.value(1)
time.sleep_ms(5)
pin3.value(0)
time.sleep_ms(5)
pin4.value(0)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(1)
time.sleep_ms(5)
pin3.value(1)
time.sleep_ms(5)
pin4.value(0)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(0)
time.sleep_ms(5)
pin3.value(1)
time.sleep_ms(5)
pin4.value(1)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(0)
time.sleep_ms(5)
pin3.value(0)
time.sleep_ms(5)
pin4.value(1)
time.sleep_ms(5)
elif arah == 'CCW':
pin1.value(1)
time.sleep_ms(5)
pin2.value(0)
time.sleep_ms(5)
pin3.value(1)
time.sleep_ms(5)
pin4.value(0)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(0)
time.sleep_ms(5)
pin3.value(0)
time.sleep_ms(5)
pin4.value(1)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(0)
time.sleep_ms(5)
pin3.value(1)
time.sleep_ms(5)
pin4.value(1)
time.sleep_ms(5)
pin1.value(0)
time.sleep_ms(5)
pin2.value(1)
time.sleep_ms(5)
pin3.value(1)
time.sleep_ms(5)
pin4.value(0)
time.sleep_ms(5)
# Gerakan motor