Skip to content

Instantly share code, notes, and snippets.

@ditwoo
Created January 24, 2024 08:52
Show Gist options
  • Save ditwoo/628667972111ea21865625be55e1a8cd to your computer and use it in GitHub Desktop.
Save ditwoo/628667972111ea21865625be55e1a8cd to your computer and use it in GitHub Desktop.
#
# Source: https://thepihut.com/blogs/raspberry-pi-tutorials/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins
#
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function
pinLED = 27 # LED GPIO Pin LED
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) # Pause 1 second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment