import RPi.GPIO as GPIO
import time
switch_pin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(switch_pin, GPIO.IN)
print("Press Ctrl+C to stop")
try:
while True:
if GPIO.input(switch_pin):
print("Switch Pressed")
else:
print("Switch Released")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()