我在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)我收到这样的信息:
回溯(最近一次调用):File "",第10行IndentationError: un缩进不匹配任何外部缩进级别,您能帮我吗?
发布于 2021-02-22 15:16:41
您需要正确地缩进代码:
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)发布于 2021-02-22 11:28:34
不妨试试这个:
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)我只是更改了如果button.value():4个空格的话,那么它在while true:循环中。
https://stackoverflow.com/questions/66242466
复制相似问题