User manual
95
The actual round is displayed in the Python Shell window
for i in range(round):
LEDOn(color[i], 1)
Now the program performs the pattern that the player has to remember. Depending on the actual number of
rounds, LEDs light up one after the other in the random colours according to the list
colour which was set
up in the program previously. Since the counter
round starts with 1, one LED is already lit in the first round.
To illuminate the LED, the function
LEDOn() is used that uses as the first parameter the colour from the
corresponding list position, the second parameter lets each LED light up for one second.
for i in range(round): When the colour pattern has been played, another loop starts and here the player
has to reproduce the memorized pattern using the buttons.
button = push() This calls the function Push() with a waiting period until the player has pressed a button.
The number of the button pressed is stored in the variable
button
LEDOn(button, 0.2) When a button is pressed the associated LED is lit for 0.2 seconds.
if(button != color[i]): If the last button pressed does not match the colour at the corresponding
position in the list, the player has lost. The operator
!= stands for not equal. Here also <> can be used.
print “Lost!"
print “You have made it to round", round – 1, “success"
The program displays on-screen that the player has lost and the number of rounds managed to play. The
number of rounds passed is one less than the current round counter.
for j in range(4):
GPIO.output(LED[j], True)
As an optically visible sign all LEDs are switched on ...
for j in range(4):
time.sleep(0.5); GPIO.output(LED[j], False)
... Then one after another at intervals of 0.5 seconds they are turned off again. This results in a significant
reduction effect.
ok = False The variable ok that identifies whether the player is still playing is set to False ...
break ... and the loop is aborted. The player can no longer press a button. The first mistakes ends the game.
if(ok == False):
break
If ok is on False the outer loop is aborted and no other rounds follow.