认识开发板 XIAO ESP32S3 (Sense)
系统固件:circuitPython :
Welcome To CircuitPython | Welcome to CircuitPython! | Adafruit Learning System
Welcome To CircuitPython | Welcome to CircuitPython! | Adafruit Learning System
编辑器:thonny :
任务一:(板载)LDE闪烁
Import time
from board import IO21
from digitalio import DigitalInOut, Direction # 使用digitalio库来设置引脚方向
led = DigitalInOut(IO21) # 初始化内置LED引脚
led.direction = Direction.OUTPUT # led 引脚设置为输出模式
while True:
led.value = True # 打开LED
time.sleep(1) # 等待1秒
led.value = False # 关闭LED
time.sleep(1) # 等待1秒
任务二:按钮LED灯
Import time
from board import IO1,IO2
from digitalio import DigitalInOut, Direction, Pull
# 初始化内置LED引脚为输出模式
led = DigitalInOut(IO2)
led.direction = Direction.OUTPUT
# 开关按钮 设置 IO1
button = DigitalInOut(IO1)
button.direction = Direction.INPUT
button.pull = Pull.UP
while True:
if button.value:
led.value = False
else:
led.value = True
time.sleep(0.01) # 防抖动延迟
综合任务:DIY键盘
Import time
import board
import usb_hid
from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
# 初始化键盘设备
kbd = Keyboard(usb_hid.devices)
# 设置复制按钮 IO1
button_copy = DigitalInOut(board.IO1)
button_copy.direction = Direction.INPUT
button_copy.pull = Pull.UP
# 设置粘贴按钮 IO6
button_paste = DigitalInOut(board.IO6)
button_paste.direction = Direction.INPUT
button_paste.pull = Pull.UP
while True:
if not button_copy.value: # 如果按钮copy 被按下
kbd.send(Keycode.CONTROL, Keycode.C) # 发送 ctrl+c
print('c')
time.sleep(0.3) # 防止按键重复
elif not button_paste.value: # 如果按钮paste 被按下
kbd.send(Keycode.CONTROL, Keycode.V) # 发送 ctrl+v
print('v')
time.sleep(0.3) # 防止按键重复
time.sleep(0.1) # 防抖动延迟