I am trying to create a game on a raspberry pi using a breadboard, LEDs and a couple buttons. What I would like the code to do is turn 2 LEDs on at the same time (one for each player) then take the reaction time and average it to see who has the lowest average at the end of the round. The issue I am running into is that running the for loop the way I have it now always has to have button 1 (btn1) pressed first before moving down in the code. Is there a way to be able to read both buttons simultaneously?
from gpiozero import Button, LED
from time import time, sleep
from random import randint
btn1 = Button(27)
led1 = LED (17)
total1 = 0
btn2= Button(26)
led2 = LED(13)
total2 = 0
for x in range(3):
sleep(randint(1,2))
start = time()
led1.on()
led2.on()
btn1.wait_for_press()
led1.off()
end1 = time()
btn2.wait_for_press()
led2.off()
end2 = time()
reaction_time1 = end1-start
reaction_time2 = end2-start
print('PLayer 1: you took', reaction_time1,'seconds')
total1=total1+reaction_time1
print('Player 1 average is', total1/(x+1), 'seconds')
reaction_time1=end1-start
print('PLayer 2: you took', reaction_time2,'seconds')
total2=total2+reaction_time2
print('Player 2 average is', total2/(x+1), 'seconds')
reaction_time2=end2-start