Fix jittering and cleanup

This commit is contained in:
2025-09-23 22:58:21 +02:00
parent acb3116c69
commit 7448c9aeb7
3 changed files with 54 additions and 50 deletions

View File

@@ -1,11 +1,9 @@
import RPi.GPIO as GPIO
import time
# ----------------------------
# Setup
# ----------------------------
GPIO.setmode(GPIO.BCM) # Use BCM numbering
PIN = 26 # The pin you want to monitor (BCM26)
GPIO.setmode(GPIO.BCM)
PIN = 26
# Setup pin as input with pull-up
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
@@ -14,15 +12,14 @@ print(f"Monitoring GPIO{PIN}. Press Ctrl+C to exit.")
try:
while True:
if GPIO.input(PIN): # Pin is HIGH (1)
if GPIO.input(PIN):
print(f"GPIO{PIN} is HIGH")
else: # Pin is LOW (0)
else:
print(f"GPIO{PIN} is LOW")
time.sleep(0.1) # Check every 100 ms
time.sleep(0.5)
except KeyboardInterrupt:
print("Exiting...")
finally:
GPIO.cleanup()