Exemple #1
0
def validated_input(color_string, guess):
    if color_string == guess:
        print 'good job keep going'
    else:
        print 'u got it wrong ur answer was ', guess
        print ' the right answer was', color_string
        LED.destroy()
        exit()
Exemple #2
0
def validate_guess(color_string_seq, guess):
    if guess != color_string_seq:
        print "Gameover"
        print "The correct sequence was: ", color_string_seq
        LED.noColor()
        LED.destroy()
        exit()
    else:
        pass     
Exemple #3
0
def validate_guess(color_sequence_string, guess):
	if guess == color_sequence_string:
		print"Correct, here is the next color sequence"
	else:
		print "Incorrect guess"
		print "The correct sequence is ", color_sequence_string
		print "Your guess was: ", guess
		LED.destroy()
		exit()
Exemple #4
0
def validateGuess(color, guess):
    if color == guess.upper():
        print "Correct!"
    else:
        print "You lose!"
        print "It was", color, "and you guessed", guess.upper()
        print "You were on level", len(color_s)
        LED.destroy()
        Buzz.stop()
        exit()
Exemple #5
0
def playColorList():
    for i in range(0, len(colorList)):
        Buzz.ChangeFrequency(220 * (2**colors.index(colorList[i])))
        Buzz.start(50)
        LED.setColor(colorList[i])
        #print colorList[i]
        time.sleep(0.5)
        Buzz.stop()
        LED.noColor()
        time.sleep(0.5)
    print ' '
Exemple #6
0
def validate_guess(color_sequence_string, guess):
    if color_sequence_string == guess:
        print 'Correct'
    else:
        print 'Incorrect'
        print "The correct sequence is: ", color_sequence_string
        print "Your guess was: ", guess
        Buzz.ChangeFrequency(480)
        Buzz.start(50)
        time.sleep(0.5)
        Buzz.stop()
        LED.destroy()
        exit()
Exemple #7
0
def validate_guess(color_sequence_string, guess):
    if guess == color_sequence_string:
        print 'Correct'
    else:
        print 'Game Over'
        Buzz.ChangeFrequency(frequencies[4])
        Buzz.start(50)
        time.sleep(0.5)
        Buzz.stop()
        print 'Your guess was:', guess
        print 'The correct sequence was:', color_sequence_string
        LED.destroy()
        exit()
Exemple #8
0
def validate_guess(color_string, guess):
    if guess == color_string:
        print 'Good Job!'
    else:
        print 'Wrong! Game Over'
        Buzz.ChangeFrequency(300)
        Buzz.start(50)
        time.sleep(0.5)
        Buzz.stop()
        print 'Correct Sequence: ', color_string
        print 'Your answer: ', guess
        LED.destroy()
        exit()
Exemple #9
0
def loop():
    n = random.randint(0, 3)
    color_sequence = [colors[n]]
    while True:
        for i in range(0, len(color_sequence)):
            Buzz.ChangeFrequency(frequencies[n])
            Buzz.start(50)
            time.sleep(0.5)
            LED.setColor(color_sequence[n])
            Buzz.stop()
            time.sleep(0.5)
            LED.noColor()
            time.sleep(0.2)
        n = random.randint(0, 3)
        color_sequence.append(colors[n])
        time.sleep(0.3)
Exemple #10
0
def append_list():
    while True:
        n = random.randint(0,3)
        color_sequence.append(colors[n])
        frequency_sequence.append(frequencies[n])
        for i in range(0, len(color_sequence)):
            Buzz.ChangeFrequency(frequency_sequence[i])
            Buzz.start(50)
            LED.setColor(color_sequence[i]) 
            time.sleep(0.5)
            Buzz.stop()
            LED.noColor()
            time.sleep(0.5)
        guess = getpass("Guess the color sequence")  
        color_sequence_string=''.join(color_sequence)
        validate_guess(color_sequence_string,guess.upper())
Exemple #11
0
def loop():
    while True:
        n = random.randint(0, 3)
        previous.append(n)
        color_sequence = (colors[n])
        for i in previous:
            LED.setColor(colors[i])
            Buzz.ChangeFrequency(frequencies[i])
            Buzz.start(25)
            time.sleep(1)
            Buzz.stop()
            LED.noColor()
            time.sleep(1)
        guess = getpass("guess the colors")
        color_sequence_string = ''.join(color_sequence)
        validateGuess(color_sequence_string, guess.upper())
Exemple #12
0
def append_list():
    while True:
        n = random.randint(0, 3)
        colorlist.append(n)
        color_s.append(colors[n])
        for i in colorlist:
            LED.setColor(colors[i])
            Buzz.ChangeFrequency(frequencies[i])
            Buzz.start(10)
            time.sleep(0.5)
            LED.noColor()
            Buzz.stop()
            time.sleep(0.5)
        guess = getpass("Guess the color sequence: ")
        colorString = ''.join(color_s)
        validateGuess(colorString, guess)
Exemple #13
0
def colorpart():
    counter = 0
    while counter == 0:
        n = random.randint(0, 3)
        colorr.append(colors[n])
        frequency_list.append(frequencies[n])
        for x in range(0, len(colorr)):
            Buzz.ChangeFrequency(frequency_list[x])
            Buzz.start(50)
            LED.setColor(colorr[x])
            time.sleep(0.15)
            Buzz.stop()
            LED.noColor()
            time.sleep(0.1)
        guess = getpass('say this color sequence: ')
        color_string = ''.join(colorr)
        validated_input(color_string, guess.upper())
Exemple #14
0
 def loop():
     n = random.randint(0, 3)
     n = y
     c_seq = [colors[n]]
     while True:
         for color in c_seq:
             Buzz.ChangeFrequency(freq[n])
             Buzz.start(50)
             LED.setColor(color)
             time.sleep(0.5)
             Buzz.stop()
             LED.noColor()
             time.sleep(0.5)
         guess = getpass('Guess the color sequence?(r,g,b,y)')
         c_seq_string = ''.join(c_seq)
         validate_guess(c_seq_string, guess.upper())
         n = random.randint(0, 3)
         c_seq.append(colors[n])
         time.sleep(0.5)
Exemple #15
0
def loop():
    n = random.randint(0,3) 
    color_string = [colors[n]]
    freq_string = [frequencies[n]]
    while True:
        for i in range(len(color_string)):
            Buzz.ChangeFrequency(freq_string[i])
            Buzz.start(50)
            LED.setColor(color_string[i])
            time.sleep(0.5)
            Buzz.stop()
            LED.noColor()
            time.sleep(0.5)
        guess = getpass("What was the color sequence") 
        color_string_seq = ''.join(color_string)
        validate_guess(color_string_seq, guess.upper())
        n = random.randint(0,3)
        color_string.append(colors[n])
        freq_string.append(frequencies[n])
        time.sleep(0.5)   
Exemple #16
0
def simonsays():

    while True:
        n = random.randint(0, 3)
        colorlist.append(colors[n])
        soundlist.append(frequencies[n])
        p = len(colorlist)
        x = 0
        while p > 0:
            LED.setColor(colorlist[x])
            Buzz.ChangeFrequency(soundlist[x])
            Buzz.start(1)
            time.sleep(.5)
            Buzz.stop()
            LED.noColor()
            time.sleep(.5)
            p = p - 1
            x = x + 1
        guess = getpass("Guess the color sequence: ")
        colorstring = "".join(colorlist)
        validate_guess(colorstring, guess.upper())
Exemple #17
0
def validate_guess(color_sequence_string, guess):
	if guess == color_sequence_string:
		print 'Correct! Here is the next sequence' 
		
	else:
		print 'Wrong!'
		print ('the correct sequence is', color_sequence_string)
		print ('your guess was', guess)
		Buzz.ChangeFrequency (55) 
		Buzz.start(50)
		LED.setColor(colors[0])
		time.sleep(0.5)
		LED.setColor(colors[1])
		time.sleep(0.5)
		LED.setColor(colors[2])
		time.sleep(0.5)
		LED.setColor(colors[3])
		time.sleep(0.5)
		Buzz.stop()
		LED.destroy()
		exit()
Exemple #18
0
def simonsays():
    print "Input the color sequence like: rbbgygp \nr = red, b = blue, g = green, y = yellow, and p = pink"
    while True:
        n = random.randint(0, 4)
        colorlist.append(colors[n])
        soundlist.append(frequencies[n])
        p = len(colorlist)
        x = 0
        while p > 0:
            LED.setColor(colorlist[x])
            Buzz.ChangeFrequency(soundlist[x])
            Buzz.start(1)
            time.sleep(.5)
            Buzz.stop()
            LED.noColor()
            #time.sleep(1)
            p = p - 1
            x = x + 1
        guess = getpass("Guess the color sequence: ")
        colorstring = ''.join(colorlist)
        validate_guess(colorstring, guess.upper())
def append_list():
    g = 0
    Round = 0
    colors = []
    frequencies = []
    while True:
        time.sleep(1)
        n = random.randint(0, 3)
        g = g + 1
        if n == 0:
            a = 'R'
            b = 220
        elif n == 1:
            a = 'G'
            b = 440
        elif n == 2:
            a = 'B'
            b = 880
        elif n == 3:
            a = 'Y'
            b = 1760
        colors.append(a)
        frequencies.append(b)
        color_string = ''.join(colors)
        i = 0
        loop = False
        while loop == False:
            LED.setColor(colors[i])
            Buzz.ChangeFrequency(frequencies[i])
            Buzz.start(50)
            time.sleep(0.5)
            LED.noColor()
            Buzz.stop()
            time.sleep(0.5)
            i = i + 1
            if i == g:
                loop = True
        guesses = []
        i = 0
        h = 1
        loop = False
        print 'Round', Round
        while loop == False:
            print 'Guess color #', h
            rinput = raw_input('(Choices: R, G, B, or Y) ')
            guesses.append(rinput)
            i = i + 1
            h = h + 1
            if i == g:
                loop = True
        if guesses == colors:
            print 'You are correct!\n\n\n\n\n\n\n\n\n'
            print colors
            Round = Round + 1
        else:
            print 'The colors were ', colors
            LED.destroy()
            exit()
Exemple #20
0
def blink_lights():
    n = random.randint(0, 3)
    color_sequence = [colors[n]]
    freq_sequence = [freq[n]]
    while True:
        for i in range(0, len(color_sequence)):
            LED.setColor(color_sequence[i])
            time.sleep(0.5)
            Buzz.ChangeFrequency(freq_sequence[i])
            Buzz.start(50)
            time.sleep(0.5)
            Buzz.stop()
            LED.noColor()
            time.sleep(0.3)
        userGuess = getpass(
            "Type in the color sequence\n'r' for red, 'b' for blue, 'g' for green, 'y' for yellow"
        )
        color_sequence_string = ''.join(color_sequence)
        validate_guess(color_sequence_string, userGuess.upper())
        n = random.randint(0, 3)
        color_sequence.append(colors[n])
        freq_sequence.append(freq[n])

        time.sleep(1)
Exemple #21
0
def validate_guess(colorstring, guess):
    colorstring.strip()
    guess.strip()
    if colorstring == guess:
        print "Correct!"
    else:
        print "You Lose"
        print "The answer was: " + colorstring
        print "You answered:   " + guess
        y = 3
        while y > 0:
            LED.setColor('R')
            Buzz.ChangeFrequency(25)
            Buzz.start(1)
            time.sleep(2)
            y = y - 1
        Buzz.stop()
        LED.noColor()
        LED.destroy()
        exit()
Exemple #22
0
import RPi.GPIO as GPIO
import LEDRGB as LED
import time
import random
# this script blinks one of four random colors on the GB LED
# colors are R = red, G = green, B = blue, Y = yellow
colors = ['R', 'G', 'B', 'Y']
R_pin = 11
G_pin = 12
B_pin = 13
LED.setup(R_pin, G_pin, B_pin)

n = random.randint(0, 3)
LED.setColor(colors[n])
time.sleep(0.5)
LED.noColor()
time.sleep(0.5)
LED.destroy()
Exemple #23
0
def loop():
    while True:
        n = random.randint(0, 3)
        ls.append(colors[n])
        #print "randcolor=", colors[n]
        lssound.append(sounds[n])
        for i in range(len(ls)):
            Buzz.ChangeFrequency(lssound[i])
            LED.setColor(ls[i])
            #print "colorstring=", ls[i]
            color_string = ''.join(ls)
            color_string = color_string.upper()
            Buzz.start(50)
            time.sleep(.5)
            LED.noColor()
            Buzz.stop()
            #time.sleep(.2)
        guess = getpass('What is the color sequence?')
        guess = guess.upper()
        #print guess

        if guess == color_string:
            print "Yay! Let's continue."
        else:
            print 'Game Over. The sequence was:', color_string
            print 'You said:', guess
            print "Play again? y/n"
            answer = raw_input()
            if answer == 'y':

                LED.noColor()
                LED.destroy()
            elif answer == 'n':
                print 'Goodbye!'
                exit()
                LED.noColor()
                LED.destroy()
Exemple #24
0
import time
import random
import RPi.GPIO as GPIO
import LEDRGB as LED
from getpass import getpass
buzz_pin = 32
R_pin = 11
G_pin = 12
B_pin = 13
LED.setup(R_pin, G_pin, B_pin)
GPIO.setup(buzz_pin, GPIO.OUT)
Buzz = GPIO.PWM(buzz_pin, 1000)
colors = ['R', 'G', 'B', 'Y']
sounds = [20, 40, 10, 50]
ls = []
lssound = []


def loop():
    while True:
        n = random.randint(0, 3)
        ls.append(colors[n])
        #print "randcolor=", colors[n]
        lssound.append(sounds[n])
        for i in range(len(ls)):
            Buzz.ChangeFrequency(lssound[i])
            LED.setColor(ls[i])
            #print "colorstring=", ls[i]
            color_string = ''.join(ls)
            color_string = color_string.upper()
            Buzz.start(50)
Exemple #25
0
import time
import random
import RPi.GPIO as GPIO
import LEDRGB as LED
from getpass import getpass

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

colors = ['R', 'G', 'B', 'Y']
freq = [220, 440, 880, 1760]

R_pin = 11
G_pin = 12
B_pin = 13
LED.setup(R_pin, G_pin, B_pin)
buzz_pin = 32

GPIO.setup(buzz_pin, GPIO.OUT)
Buzz = GPIO.PWM(buzz_pin, 1000)

print "Welcom to Simon Says! To quit the game, press control + C"


def validate_guess(color_sequence_string, guess):
    if color_sequence_string == guess.upper():
        print "Correct"
    else:
        exit()

Exemple #26
0
#Buzzer stuff
buzz_pin = 32
GPIO.setup(buzz_pin, GPIO.OUT)
Buzz = GPIO.PWM(buzz_pin, 1000)
frequencies = [220, 440, 880, 1760]

colors = ['R', 'G', 'B', 'Y']
colorList = []
gameOver = False

#LED stuff
R_pin = 11
G_pin = 12
B_pin = 13
LED.setup(R_pin, G_pin, B_pin)


def addNewColor():
    n = random.randint(0, 3)
    colorList.append(colors[n])


def playColorList():
    for i in range(0, len(colorList)):
        Buzz.ChangeFrequency(220 * (2**colors.index(colorList[i])))
        Buzz.start(50)
        LED.setColor(colorList[i])
        #print colorList[i]
        time.sleep(0.5)
        Buzz.stop()