ESP32 C3和MP3模块接线方法,请参考下面这个文章:
物联网开发118 - Micropython ESP32 C3连接Mini MP3 Player 播放器模块_魔都飘雪的博客-优快云博客
ESP32 C3和SR505模块接线方法:
三、演示代码
SR505_example.py
from machine import Pin,UART
import time
# 定义led灯对象
led = Pin(12,Pin.OUT)
# 定义SR505人体感应器对象
sr505 = Pin(4,Pin.IN,Pin.PULL_DOWN)
# 创建串口对象
uart = UART(1,baudrate = 9600,tx = 0,rx = 1)
# 命令
on = bytearray(b'\x7e\xff\x06\x03\x00\x00\x01\xfe\xf7\xef') # 开启
off = bytearray(b'\x7e\xff\x06\x03\x00\x00\x02\xfe\xf6\xef') # 关闭
# 创建SR505对象
def SR505():
if sr5.value() == True:
time.sleep(0.05)
if sr5.value() == True:
led.value(not led.value())
if led.value():
uart.write(on)