import RPi.GPIO as GPIO
import time
#Setting GPIO mode to BOARD in order to use on-board GPIO numbering
GPIO.setmode(GPIO.BOARD)
#Setting 13 as an input for the push button
#Setting 11 as an output for the LED
GPIO.setup(13,GPIO.IN)
GPIO.setup(11,GPIO.OUT)
#Infinite while statement so the script doesnt end, containing checks for the button being pushed, and turning the LED on/off
while True:
print ("Off")
GPIO.output(11, GPIO.LOW)
while GPIO.input(13) == 1:
time.sleep(0.1)
print ("On")
GPIO.output(11, GPIO.HIGH)
while GPIO.input(13) == 0:
time.sleep(0.1)
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function
pinLED = 4 # LED GPIO Pin
GPIO.setmode(GPIO.BCM) # Use GPIO pin number
GPIO.setwarnings(False) # Ignore warnings in our case
GPIO.setup(pinLED, GPIO.OUT) # GPIO pin as output pin
while True: # Endless Loop
GPIO.output(pinLED, GPIO.HIGH) # Turn on
print(LED on) # Prints state to console
sleep(1) # Pause 1 second
GPIO.output(pinLED, GPIO.LOW) # Turn off
print(LED off) # Prints state to console
sleep(1)