diff --git a/button/test.py b/button/test.py new file mode 100644 index 0000000..c7a81b3 --- /dev/null +++ b/button/test.py @@ -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!") \ No newline at end of file diff --git a/touch/test.py b/button/touch_test.py similarity index 100% rename from touch/test.py rename to button/touch_test.py