Python 3.x RPi上的Python 3瓶子int()的文本无效,基数为10:';favicon.ico';
我最近买了一本覆盆子皮和一本书(覆盆子皮食谱)。其中一个项目是通过网页控制RPi上的GPIO引脚。当我在输入代码后第一次运行代码时,我收到了一系列错误,因此,我尝试运行books github页面上列出的代码:Python 3.x RPi上的Python 3瓶子int()的文本无效,基数为10:';favicon.ico';,python-3.x,raspberry-pi,bottle,Python 3.x,Raspberry Pi,Bottle,我最近买了一本覆盆子皮和一本书(覆盆子皮食谱)。其中一个项目是通过网页控制RPi上的GPIO引脚。当我在输入代码后第一次运行代码时,我收到了一系列错误,因此,我尝试运行books github页面上列出的代码: from bottle import route, run import RPi.GPIO as GPIO host = '192.168.1.8' GPIO.setmode(GPIO.BCM) led_pins = [18, 23, 24] led_states = [0, 0,
from bottle import route, run
import RPi.GPIO as GPIO
host = '192.168.1.8'
GPIO.setmode(GPIO.BCM)
led_pins = [18, 23, 24]
led_states = [0, 0, 0]
switch_pin = 25
GPIO.setup(led_pins[0], GPIO.OUT)
GPIO.setup(led_pins[1], GPIO.OUT)
GPIO.setup(led_pins[2], GPIO.OUT)
GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def switch_status():
state = GPIO.input(switch_pin)
if state:
return 'Up'
else:
return 'Down'
def html_for_led(led):
l = str(led)
result = " <input type='button' onClick='changed(" + l + ")' value='LED " + l + "'/>"
return result
def update_leds():
for i, value in enumerate(led_states):
GPIO.output(led_pins[i], value)
@route('/')
@route('/<led>')
def index(led="n"):
print(led)
if led != "n":
led_num = int(led)
led_states[led_num] = not led_states[led_num]
update_leds()
response = "<script>"
response += "function changed(led)"
response += "{"
response += " window.location.href='/' + led"
response += "}"
response += "</script>"
response += '<h1>GPIO Control</h1>'
response += '<h2>Button=' + switch_status() + '</h2>'
response += '<h2>LEDs</h2>'
response += html_for_led(0)
response += html_for_led(1)
response += html_for_led(2)
return response
run(host=host, port=80)
知道这是怎么回事吗?非常感谢您的帮助。您的建议是什么
print led
表演
他们说led不是整数,所以错误可能来自那里
print led