Skip to content

Instantly share code, notes, and snippets.

@Dante83
Last active August 29, 2015 14:13
Show Gist options
  • Save Dante83/68d21d493e25549a3991 to your computer and use it in GitHub Desktop.
Save Dante83/68d21d493e25549a3991 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
import Adafruit_BBIO.GPIO as GPIO
import time
import random
#Programmer: David Evans
#Description: It's a basic traditional game of red light, green light, with random numbers to change between the lights!
#When connected properly to a beaglebone black with some LEDs, this program changes the light colors to the respective
#colors of the game. Just something simple to start off with my Python Beagle Bone development. Easy program, but the
#setup was hard.
GPIO.setup("P8_13", GPIO.OUT)
GPIO.setup("P8_15", GPIO.OUT)
GPIO.setup("P8_17", GPIO.OUT)
try:
while True:
#Initialize everything but the green light to zero
print "Green light!"
GPIO.output("P8_15", GPIO.LOW)
GPIO.output("P8_17", GPIO.LOW)
GPIO.output("P8_13", GPIO.HIGH)
time.sleep(random.random() * 5)
print "Yellow light!"
GPIO.output("P8_13", GPIO.LOW)
GPIO.output("P8_15", GPIO.HIGH)
time.sleep(random.random() * 5)
print "Red Light!"
GPIO.output("P8_15", GPIO.LOW)
GPIO.output("P8_17", GPIO.HIGH)
time.sleep(random.random() * 5)
except KeyboardInterrupt:
GPIO.output("P8_13", GPIO.LOW)
GPIO.output("P8_15", GPIO.LOW)
GPIO.output("P8_17", GPIO.LOW)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment