Fix jittering and cleanup
This commit is contained in:
13
print.py
13
print.py
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user