这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 买了一个RaspberryPiPico2试玩

共1条 1/1 1 跳转至

买了一个RaspberryPiPico2试玩

助工
2024-09-07 23:16:52   被打赏 100 分(兑奖)     打赏

安装固件https://micropython.org/download/RPI_PICO2/

from machine import Pin # Import the Pin class from the machine module
from time import sleep  # Import the sleep function from the time module

# Initialize GPIO25 as an output pin, which controls the USER LED
led = Pin(25, Pin.OUT) 

# Turn off the LED initially
led.value(1) # led.on() -> high level -> light off
sleep(0.5) # Wait for 0.5 seconds

# Turn on the LED
led.value(0) # led.off() -> low level -> light on
sleep(0.5) # Wait for 0.5 seconds

# Enter an infinite loop
while True:
    # Toggle the LED state (on to off or off to on)
    led.toggle() 
    # Print the current state of the LED
    print(f"LED {'ON' if led.value() == 0 else 'OFF'}")
    sleep(0.5) # Wait for 0.5 seconds before the next toggle

微信图片_20240907230702.jpg


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]