from pyb import udelay
from machine import Pin
class Stepper:
def __init__(self, step_pin, dir_pin, step_time=200):
#初始化
self.stp = step_pin
self.dir = dir_pin
self.stp.init(Pin.OUT_PP)
self.dir.init(Pin.OUT_PP)
self.step_time = step_time # us
self.steps_per_rev = 1600
self.current_position = 0
def steps(self, step_count=1):
#驱动电机走几步
self.dir.value(0 if step_count > 0 else 1)#当step_count为正数的时候,设置dir引脚为低电平。否则为高电平。
for i in range(abs(step_count)):#发送step_count数量的脉冲
self.stp.value(1)
udelay(self.step_time)
self.stp.value(0)
udelay(self.step_time)
self.current_position += step_count#记录现在的角度请说具体的问题,图片没有上传
@kidswong999看到没
@kidswong999 问题是: NameError:name 'Pin' is not defined