Files
Your Name 2be04b6950 udpate
2025-06-20 09:42:31 +02:00

51 lines
1.1 KiB
Python

'''
____ _ _
| __ ) _ _| |_| |_ ___ _ __
| _ \| | | | __| __/ _ \| '_ \
| |_) | |_| | |_| || (_) | | | |
|____/ \__,_|\__|\__\___/|_| |_|
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!")