300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 物联网开发笔记(83)- 使用Micropython开发ESP32开发板之触控TouchPad操作

物联网开发笔记(83)- 使用Micropython开发ESP32开发板之触控TouchPad操作

时间:2023-09-05 17:17:52

相关推荐

物联网开发笔记(83)- 使用Micropython开发ESP32开发板之触控TouchPad操作

一、目的

这一节我们学习如何使用我们的ESP32开发板来学习触控TouchPad操作。

二、环境

ESP32 + Thonny + 几根杜邦线 + Win10

接线方法:

三、代码

from machine import Pin,TouchPadimport 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/en/latest/esp32/quickref.html#capacitive-touch

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。