User manual

93
if(GPIO.input(TAST[2])):
return 2
if(GPIO.input(TAST[3])):
return 3
ok = True
for round in range(1, rnumber +1):
print “Round", round
for i in TAST:
LEDOn(color[i], 1)
for i in range(round):
button = press()
LEDOn(button, 0.2)
if(button != color[i]):
print “Lost!"
print “You have made it to round", round – 1, “success"
for j in range(4):
GPIO.output(LED[j], True)
for j in range(4):
time.sleep(0.5)
GPIO.output(LED[j], False)
ok = False
break
if(ok == False):
break
time.sleep(0.5)
if(ok == True):
print “Well done!"
for i in range(5):
for j in range(4):
GPIO.output(LED[j], True)
time.sleep(0.05)
for j in range(4):
GPIO.output(LED[j], False)
time.sleep(0.05)
GPIO.cleanup()
11.1.1 How does it work?
There is much new here in the programme, however, the basics of the GPIO control are known.
rnumberl = 10 Ater the import of the modules time, random and RPi.GPIO a variable rnumber is created,
which determines the number of rounds that will be played. You can also play more than ten rounds of
course- the more rounds, the more difficult it is to remember the flashing sequence.
colour = []
for i in range(rnumber):
color.append(random.randrange(4))
The list colour uses the loop to fill in as many random numbers between 0 to 3 as rounds are played. The
method
append() is used, which is available in any list. It adds the element that is transferred as parameter
to the list.