【MicroPython ESP32】 触摸传感器使用示例
- 本示例基于
Thonny平台开发
触摸传感器
ESP32可提供多达10个触摸GPIO。 这10个触摸GPIO为 0, 2, 4, 12, 13, 14, 15, 27, 32, 33
from machine import TouchPad
触摸功能函数属于
machine模块内的TouchPad类。
- 通过Shell调试窗口查询:
MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32
Type "help()" for more information.
>>> from machine import TouchPad
>>> help(TouchPad)
object <class 'TouchPad'> is of type type
config -- <function>
read -- <function>
TouchPad.read():读取touchpad的电平。若touchpad接高电平则返回1,若接GND则返回0。TouchPad.config(value):设置触摸板的标识。
value:任意整数值
示例代码
'''ESP32可提供多达10个触摸GPIO。 这10个触摸GPIO为 0, 2, 4, 12, 13, 14, 15, 27, 32, 33
'''
from machine import TouchPad,Pin
from utime import sleep #延时
led = Pin(2,Pin.OUT)#用machine模块的pin功能设置引脚2为输出。
tp = TouchPad(Pin(12))
while True:
value=tp.read()
if value > 80:
led.value(0)
else:
led.value(1)
print(value)
sleep(1)
- Shell调试窗口输出信息


4600

被折叠的 条评论
为什么被折叠?



