Last active
December 20, 2015 14:09
-
-
Save drewcassidy/6143868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import random | |
import time | |
import sys | |
#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 = [22, 24, 23, 21] | |
lights = [16, 18, 13, 11] | |
beeps = [] | |
pushes = [] | |
def levelgen(): | |
beeps.append(random.randrange(1, 5, 1)) | |
def level(): | |
levelgen() | |
prev = 0 | |
for i in range(1, 5): | |
GPIO.output(lights[i], GPIO.LOW) | |
for i in beeps: | |
GPIO.output(lights[i], GPIO.HIGH) | |
time.sleep(0.5) | |
GPIO.output(lights[i], GPIO.LOW) | |
time.sleep(0.1) | |
while len(pushes) <= len(beeps): | |
for k, v in enumerate(beeps): | |
for i in range(1,5): | |
if (GPIO.input(buttons[i]) == 0): | |
if i != v: | |
gameover() | |
pushes.append(i) | |
def gameover(): | |
running = False | |
sys.exit() | |
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() | |
time.sleep(2) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment