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

51
button/test.py Normal file
View File

@@ -0,0 +1,51 @@
'''
____ _ _
| __ ) _ _| |_| |_ ___ _ __
| _ \| | | | __| __/ _ \| '_ \
| |_) | |_| | |_| || (_) | | | |
|____/ \__,_|\__|\__\___/|_| |_|
Button connected to GND and GPIO6
/usr/bin/python3 /var/www/moduleair_pro_4g/button/test.py
'''
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
BUTTON_PIN = 6
# Cleanup first
try:
GPIO.cleanup()
except:
pass
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("Testing GPIO6 - Press the button to see state changes")
print("Press Ctrl+C to exit\n")
try:
last_state = GPIO.HIGH
while True:
current_state = GPIO.input(BUTTON_PIN)
if current_state != last_state:
if current_state == GPIO.LOW:
print("Button PRESSED!")
else:
print("Button RELEASED!")
last_state = current_state
time.sleep(0.01) # Small delay to reduce CPU usage
except KeyboardInterrupt:
print("\nCleaning up...")
GPIO.cleanup()
print("Done!")

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()