from machine import Pin
import time
time.sleep(0.1) # Wait for USB to become ready
motor_Ap = Pin(14, Pin.OUT)
motor_An = Pin(15, Pin.OUT)
motor_Bp = Pin(16, Pin.OUT)
motor_Bn = Pin(17, Pin.OUT)
current_step = 0
current_rev = 0
step_per_rev = 200
while True:
motor_Ap(1)
motor_Bp(0)
motor_An(0)
motor_Bn(0)
time.sleep(0.01)
current_step +=1
motor_Ap(0)
motor_Bp(1)
motor_An(0)
motor_Bn(0)
time.sleep(0.01)
current_step +=1
motor_Ap(0)
motor_Bp(0)
motor_An(1)
motor_Bn(0)
time.sleep(0.01)
current_step +=1
motor_Ap(0)
motor_Bp(0)
motor_An(0)
motor_Bn(1)
time.sleep(0.01)
current_step +=1
if(current_step%step_per_rev ==0):
current_rev +=1
current_step =0
print(current_rev)
time.sleep(2)