Skip to content

Instantly share code, notes, and snippets.

@TheRealEdDawson
Last active November 7, 2022 15:47
Show Gist options
  • Save TheRealEdDawson/5236983 to your computer and use it in GitHub Desktop.
Save TheRealEdDawson/5236983 to your computer and use it in GitHub Desktop.
LED Randomizer for Raspberry Pi.
import RPi.GPIO as GPIO, time
import random
# Setting up random seed variables
random.seed()
ledresult = 1
# Setting up some structures for the Raspberry Pi LED controls
GPIO.setmode(GPIO.BCM)
GREEN_LED = 18
RED_LED = 23
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)
# Main program
try:
while True:
ledresult = random.randint(1,4)
if ledresult == 1:
GPIO.output(GREEN_LED, False)
GPIO.output(RED_LED, False)
if ledresult == 2:
GPIO.output(GREEN_LED, True)
GPIO.output(RED_LED, False)
if ledresult == 3:
GPIO.output(GREEN_LED, False)
GPIO.output(RED_LED, True)
if ledresult == 4:
GPIO.output(GREEN_LED, True)
GPIO.output(RED_LED, True)
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
print "Clean program exit."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment