Thonny
平台开发ESP32可提供多达10个触摸GPIO。 这10个触摸GPIO为 0, 2, 4, 12, 13, 14, 15, 27, 32, 33
触摸功能函数属于
machine
模块内的TouchPad
类。
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)