模組簡介
TTP223 is a touch pad detector https://www.electroschematics.com/ttp223-capacitive-touch-switch-circuit/
電路圖
程式列表(IO輪巡式)
Blockly
Python
"""
EPY Sensor
-----------------
3V3 VCC
GND GND
P4 OUT
VIN
CDS
"""
from machine import LED
from machine import Pin
from machine import Switch
import utime
from machine import RTC
KeyA = None
P4 = None
rtc = None
ledR = None
ledG = None
KeyA = Switch('keya')
rtc = RTC()
ledR = LED('ledr')
ledG = LED('ledg')
ledG.off()
P4 = Pin(Pin.board.P4,Pin.IN)
while True:
if (P4.value()) == 0:
ledR.toggle()
ledG.off()
else:
ledR.off()
ledG.toggle()
if (KeyA.value()) == True:
break
utime.sleep_ms( 500 )
執行結果
沒有觸摸PAD綠燈閃爍
有觸摸PAD紅燈閃爍