/ pi / switch.py
switch.py
 1  import RPi.GPIO as GPIO
 2  import time
 3  
 4  GPIO.setmode(GPIO.BCM)
 5  
 6  GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 7  
 8  while True:
 9      input_state = GPIO.input(15)
10      if input_state == False:
11          print('Button Pressed')
12          time.sleep(0.2)