「Raspberry pico w」:修訂間差異
跳至導覽
跳至搜尋
| 第13行: | 第13行: | ||
led.off() | led.off() | ||
time.sleep(1) # LED滅 | time.sleep(1) # LED滅 | ||
</python> | |||
==連上wifi== | |||
<python> | |||
import network | |||
import time | |||
# 配置您的WiFi连接信息 | |||
ssid = 'QCRD' | |||
password = 'tskdenko' | |||
# 初始化WiFi接口 | |||
wlan = network.WLAN(network.STA_IF) | |||
# 激活接口 | |||
wlan.active(True) | |||
# 连接到WiFi网络 | |||
if not wlan.isconnected(): | |||
print('正在连接到网络...') | |||
wlan.connect(ssid, password) | |||
# 等待连接 | |||
while not wlan.isconnected(): | |||
pass | |||
# 显示网络接口的状态 | |||
print('网络配置:', wlan.ifconfig()) | |||
</python> | </python> | ||
於 2024年1月4日 (四) 09:40 的修訂
參考資料
- 首頁MicroPythonRaspberry Pi Pico筆記 https://atceiling.blogspot.com/2021/03/raspberry-pi-pico1micropythonled.html
LED blink
<python> from machine import Pin import time
led = Pin("LED", Pin.OUT)
while True:
led.on() # LED亮 time.sleep(1) # 等待1秒 led.off() time.sleep(1) # LED滅
</python>
連上wifi
<python> import network import time
- 配置您的WiFi连接信息
ssid = 'QCRD' password = 'tskdenko'
- 初始化WiFi接口
wlan = network.WLAN(network.STA_IF)
- 激活接口
wlan.active(True)
- 连接到WiFi网络
if not wlan.isconnected():
print('正在连接到网络...')
wlan.connect(ssid, password)
# 等待连接
while not wlan.isconnected():
pass
- 显示网络接口的状态
print('网络配置:', wlan.ifconfig()) </python>