[英]Raspberry Pi Pico - problem with Thonny interpreter
我在编写 Raspberry Pi Pico 时遇到了麻烦。 我正在使用 Thonny IDE 和 micropython。 我只是一个初学者,所以只需从他们的网站( https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/6 )下载代码并将其安装到微控制器。 但是当我保存这段代码时:
from machine import Pin
import time
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
while True:
if button.value():
led.toggle()
time.sleep(0.5)
我收到这条消息:
Traceback(最近一次调用最后一次):文件“”,第 10 行 IndentationError:unindent 与任何外部缩进级别都不匹配,您能帮帮我吗?
您需要正确缩进代码:
from machine import Pin
import time
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
while True:
if button.value():
led.toggle()
time.sleep(0.5)
也许试试这个:
from machine import Pin
import time
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
while True:
if button.value():
led.toggle()
time.sleep(0.5)
我刚刚更改了 if button.value(): 四个空格,所以它在 while true: 循环内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.