Skip to content

Instantly share code, notes, and snippets.

@drewcassidy
Created August 2, 2013 21:08
Show Gist options
  • Save drewcassidy/6143473 to your computer and use it in GitHub Desktop.
Save drewcassidy/6143473 to your computer and use it in GitHub Desktop.
Traceback (most recent call last): File "simon.py", line 44, in <module> main() File "simon.py", line 43, in main level() File "simon.py", line 31, in level levelgen() File "simon.py", line 28, in levelgen levelNum += 1 UnboundLocalError: local variable 'levelNum' referenced before assignment
import RPi.GPIO as GPIO
import random
import time
levelNum = 0
#global levelNum
GPIO.setmode(GPIO.BOARD)
GPIO.setup(21, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
buttons = {1:22, 2:24, 3:23, 4:21}
lights = {1:16, 2:18, 3:13, 4:11}
input = {1:False, 2:False, 3:False, 4:False}
beeps = [random.randrange(1, 5, 1)]
def levelgen():
beeps.append(random.randrange(1, 5, 1))
levelNum += 1
def level():
levelgen()
for i in beeps:
GPIO.output(lights[i], GPIO.HIGH)
time.sleep(0.5)
GPIO.outut(lights[1], GPIO.LOW)
def main():
while True:
#print GPIO.input(22)
#print random.randrange(1, 5, 1)
for i in range(1,5):
input[i] = GPIO.input(buttons[i])
GPIO.output(lights[i], not GPIO.input(buttons[i]))
level()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment