from machine import Pin
from utime import sleep

direction = Pin(2, Pin.OUT)
step = Pin(4, Pin.OUT)

while True:
  # swap direction
  direction.value(1 - direction.value())
  # make 100 half-steps (one quarter turn)
  for _ in range(100):
    step.value(1 - step.value())
    sleep(0.01)
  # pause before swapping direction
  sleep(2)
A4988