我正在使用Flask停止并移动Serveo,它在控制台上没有任何错误,但仅运行2秒钟,然后电动机停止了运行。
我还添加了一个LED指示灯,当我移动电动机时该指示灯点亮,而在停止电动机时该指示灯熄灭,并且该LED指示灯工作正常。
问题:
但是不起作用的一件事是LED( sic )
(编者注:发问者可能表示“电动机”而不是“ LED” )
我的代码:https://paste.pydis.com/sunexojoji.py
from flask import Flask, render_template, session
from gpiozero import *
import datetime
import RPi.GPIO as GPIO
from time import sleep
GPIO.cleanup()
app = Flask(__name__)
led1 = LED(27)
servoPIN = 17
servoPIN2 = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
GPIO.setup(servoPIN2, GPIO.OUT)
pwm = GPIO.PWM(servoPIN2, 50) # GPIO 17 for PWM with 50Hz
pwm.start(0)
@app.route('/')
def json():
return render_template('json.html')
#background process happening without any refreshing
@app.route('/background_process_test')
def background_process_test():
led1.on()
print ("on")
return ("nothing")
@app.route('/ledoff')
def ledoff():
led1.off()
print ("off")
return("nothing")
@app.route('/forward')
def forward():
print("forward")
pwm.ChangeDutyCycle(10)
return("nothing")
@app.route('/backward')
def backward():
print("back")
@app.route('/sharpleft')
def sharpleft():
print("sharpleft")
@app.route('/sharpright')
def sharpright():
print("sharpright")
@app.route('/stopcar')
def stopcar():
print("stopcar")
pwm.ChangeDutyCycle(0)
return("nothing")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5012, debug=True)