Maybe someone will need it.
See it in action. https://www.youtube.com/watch?v=4XYBexi ... e=youtu.be
Code: Select all
import pyb
accel = pyb.Accel()
speed_x = 0
angle_x = 0
tim_x = pyb.Timer(1, freq=1)
def stepper_x(speed, angle):
global speed_x
global angle_x
if angle_x != angle:
if angle_x < angle:
angle_x += 1
pyb.Pin('X2', pyb.Pin.OUT_PP).low()
pyb.Pin('X1', pyb.Pin.OUT_PP).high()
pyb.Pin('X1', pyb.Pin.OUT_PP).low()
if angle_x > angle:
angle_x -= 1
pyb.Pin('X2', pyb.Pin.OUT_PP).high()
pyb.Pin('X1', pyb.Pin.OUT_PP).high()
pyb.Pin('X1', pyb.Pin.OUT_PP).low()
if speed_x != speed:
tim_x.init(freq = speed)
speed_x = speed
while True:
x = accel.x()
x = x * 3
tim_x.callback(lambda t:stepper_x(200, x))
pyb.delay(100)
pyb.LED(3).on()
Any suggestions welcome.