# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD) # BOARD编号方式,基于插座引脚编号
GPIO.setwarnings(False) #关闭警告说明
GPIO.setup(7, GPIO.OUT, initial=GPIO.HIGH) #将STBY为输出的引脚设置默认值为高
#***********定义轮子
AL_1 = 33 #B 后左轮电机引脚1
AL_2 = 35 #B 后左轮电机引脚2
AR_1 = 31 #B 后右轮电机引脚1
AR_2 = 29 #B 后右轮电机引脚2
BL_1 = 16 #B 后左轮电机引脚1
BL_2 = 18 #B 后左轮电机引脚2
BR_1 = 13 #B 后右轮电机引脚1
BR_2 = 15 #B 后右轮电机引脚2
GPIO.setup(33, GPIO.OUT)
GPIO.setup(35, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
#*************定义PWM
GPIO.setup(11, GPIO.OUT)
PWM = GPIO.PWM(11, 50)
PWM.start(50)
#*************定义前轮转动函数
def SUN_A(motor, direction):
pin1 = GPIO.LOW
pin2 = GPIO.HIGH
if direction == 1:
pin1 = GPIO.HIGH
pin2 = GPIO.LOW
if motor == 1:
GPIO.output(AL_1, pin1)
GPIO.output(AL_2, pin2)
else:
GPIO.output(AR_1, pin1)
GPIO.output(AR_2, pin2)
def SUN_B(motor, direction):
pin1 = GPIO.LOW
pin2 = GPIO.HIGH
if direction == 1:
pin1 = GPIO.HIGH
pin2 = GPIO.LOW
if motor == 1:
GPIO.output(BL_1, pin1)
GPIO.output(BL_2, pin2)
else:
GPIO.output(BR_1, pin1)
GPIO.output(BR_2, pin2)
def pwm(speed):
PWM.ChangeDutyCycle(speed)
def forward():
SUN_A(1, 1)
SUN_A(0, 1)
SUN_B(1, 1)
SUN_B(0, 1)
def back():
SUN_A(1, 0)
SUN_A(0, 0)
SUN_B(1, 0)
SUN_B(0, 0)
def left():
SUN_A(1, 0)
SUN_A(0, 1)
SUN_B(1, 0)
SUN_B(0, 1)
def right():
SUN_A(1, 1)
SUN_A(0, 0)
SUN_B(1, 0)
SUN_B(0, 1)
while 1 :
forward()
print(1)
#back()
#left()
#right()
上面是我的程序,我把它放在树莓派里边运行,刚开始小车轮子可以正常运动,但过一会小车轮子就不动了,但是还没退出程序while 1:如果print(1)也能打印1
这是哪里出来问题求大佬帮我打通任督二脉!!!