import RPi.GPIO as GPIO # Import library for GPIO (pin) access GPIO.setmode(GPIO.BOARD) # Specify that we use the BOARD numbers (pin numbers 1-26 on the connector) GPIO.setwarnings(False) # Disable the warning "This channel is already in use" import time GPIO.setup(22, GPIO.IN) # Configure pin 22 as an input (IN) while True: x = GPIO.input(22) # Read pin 22 and store 1 (high) or 0 (low) in x print(x) # print x. It will print either 1 or 0 time.sleep(0.25) # wait 0.25 seconds before doing the loop again