本站改版新增arduino频道
一、目的
这一节我们学习如何使用我们的ESP32开发板来学习触控TouchPad操作。
二、环境
ESP32 + Thonny + 几根杜邦线 + Win10
接线方法:

三、代码
from machine import Pin,TouchPad
import time
# 可使用的触控pin: 0,2,4,12,13,14,15,27,32,33
led=Pin(2,Pin.OUT)
tou=TouchPad(Pin(15))
def Touch():
temp = tou.read()
print("%d"%(temp))
if(temp > 10 and temp < 100):
led.value(1)
else:
led.value(0)
time.sleep(0.5)
def main():
while True:
Touch()
if __name__=="__main__":
main()四、演示效果
运行程序后,板载LED灯(使用的是GPIO2)状态为灭,当你用手或者钥匙去触摸GPIO15上的导线的时候,LED就会亮起来。
五、参考资料
官方资料:
Quick reference for the ESP32 — MicroPython latest documentation
http://docs.micropython.org/en/latest/esp32/quickref.html#capacitive-touch
————————————————
原文链接:https://blog.csdn.net/zhusongziye/article/details/129069569
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0093429088592529 seconds