This commit is contained in:
Your Name
2025-06-20 09:42:31 +02:00
parent 653129b11f
commit 2be04b6950
2 changed files with 51 additions and 0 deletions

44
button/touch_test.py Normal file
View File

@@ -0,0 +1,44 @@
'''
_____ ___ _ _ ____ _ _
|_ _/ _ \| | | |/ ___| | | |
| || | | | | | | | | |_| |
| || |_| | |_| | |___| _ |
|_| \___/ \___/ \____|_| |_|
script to test the TTP223 sensor
/usr/bin/python3 /var/www/moduleair_pro_4g/touch/test.py
'''
import RPi.GPIO as GPIO
import time
# Setup GPIO
TOUCH_PIN = 6 # GPIO06 (BCM numbering)
GPIO.setmode(GPIO.BCM)
GPIO.setup(TOUCH_PIN, GPIO.IN)
print("Touch sensor ready. Waiting for touch...")
last_state = False # Track previous state (False = not touched)
try:
while True:
current_state = GPIO.input(TOUCH_PIN) == GPIO.HIGH
# If touch state has changed
if current_state != last_state:
if current_state:
print("👋 Sensor touched!")
else:
print("🖐️ Sensor released!")
last_state = current_state # Update last state
time.sleep(0.1) # Polling interval
except KeyboardInterrupt:
print("\nExiting...")
finally:
GPIO.cleanup()