from machine import Pin
from time import sleep
# Define the pins
DIR_PIN = Pin(2, Pin.OUT)
STEP_PIN = Pin(3, Pin.OUT)
def setup():
# Initialize pins (already done in Pin object creation)
STEP_PIN.value(0) # Ensure STEP_PIN is low initially
def loop():
while True:
# Move 200 steps (one rotation) CW over one second
DIR_PIN.value(1)
for _ in range(500):
STEP_PIN.value(1)
STEP_PIN.value(0)
sleep(0.005) # 5 ms
sleep(0.5)
for _ in range(100):
STEP_PIN.value(1)
STEP_PIN.value(0)
sleep(0.005) # 5 ms
sleep(0.5) # Wait half a second
# Move 200 steps (one rotation) CCW over 400 milliseconds
DIR_PIN.value(0)
for _ in range(500):
STEP_PIN.value(1)
STEP_PIN.value(0)
sleep(0.002) # 2 ms
sleep(1) # Wait another second
# Run the setup and loop
setup()
loop()