# https://wokwi.com/projects/445356419189544961
from machine import Pin
from time import sleep
IN1 = Pin(2, Pin.OUT)
IN2 = Pin(3, Pin.OUT)
IN3 = Pin(4, Pin.OUT)
IN4 = Pin(5, Pin.OUT)
pins = [IN1, IN2, IN3, IN4]
# Full-step sequence (clockwise)
sequence = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
def rotate_steps(steps):
for _ in range(steps):
for step in sequence:
for i in range(len(pins)):
pins[i].value(step[i])
sleep(0.002)
# Rotate 1 full revolution (2048 steps)
rotate_steps(2048)
# Stop motor by de-energizing all coils
for pin in pins:
pin.value(0)