import RPi.GPIO as GPIO import time # set up the GPIO pin GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) # turn the LED on and off repeatedly while True: GPIO.output(18, GPIO.HIGH) # turn LED on time.sleep(1) # wait for 1 second GPIO.output(18, GPIO.LOW) # turn LED off time.sleep(1) # wait for 1 second
import RPi.GPIO as GPIO # set up the GPIO pin GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # read the value of the GPIO pin while True: if GPIO.input(18) == GPIO.HIGH: print("Button Pressed")In both examples, the package library used is RPi.GPIO.