# Stepper Motor Control from machine import Pin, Timer import time tim = Timer() Step = 0 Ref = 0 pin1 = Pin(15,Pin.IN,Pin.PULL_UP) pin2 = Pin(14,Pin.IN,Pin.PULL_UP) Sa = Pin(6,Pin.OUT) Sb = Pin(7,Pin.OUT) Sc = Pin(8,Pin.OUT) Sd = Pin(9,Pin.OUT) def Stepper(Step): X = Step % 4; if(X == 0): Sa.value(1) Sb.value(0) Sc.value(0) Sd.value(0) if(X == 1): Sa.value(0) Sb.value(1) Sc.value(0) Sd.value(0) if(X == 2): Sa.value(0) Sb.value(0) Sc.value(1) Sd.value(0) if(X == 3): Sa.value(0) Sb.value(0) Sc.value(0) Sd.value(1) def tick(timer): global Step, Ref if(Step < Ref): Step += 1 if(Step > Ref): Step -= 1 Stepper(Step) tim.init(freq=100, mode=Timer.PERIODIC, callback=tick) while (1): if(pin1.value() == 0): Ref = 0 if(pin2.value() == 0): Ref = 100 print(Ref, Step, ) time.sleep(0.1)