树莓派控制步进电机

import time
import RPi.GPIO as gpio
pin=[11,13,15,16]
gpio.setmode(gpio.BOARD)
gpio.setup(pin,gpio.OUT)
def go(pin):
    for i in range(4):
        x=[0,0,0,0]
        x[i]=1
        gpio.output(pin,x)
        time.sleep(0.01)

def back(pin):
    for i in range(4):
        x=[0,0,0,0]
        x[i]=1
        gpio.output(pin,x[::-1])
        time.sleep(0.01)
for i in range(100):
    go(pin)

time.sleep(5)
for i in range(100):
    back(pin)

gpio.cleanup()

转载于:https://www.cnblogs.com/3day/articles/6847378.html

你可能感兴趣的:(树莓派控制步进电机)