I recently found the Rpi bought one, and started a project making a lap counter to my slotrace track.
And that works really fine, I using phototransistors and inputs from GPIO.
But I cannot find out how to get the mouse/touchscreen or tha keyboard to work at the same time, on my pc where i disabled the GPIO the keybord/mouse work fine.
I think the for event in pygame.event.get() and the GPIO.add_event_detect is the problem.
if I remove the for event in pygame.event.get() the program works fine just counting.
explaining the code: I make detections on the GPIO and that detection show the laptime, the fastest lap time and the number of laps.
I want to be able to touch the screen (480x320) within one of the 6 fields to reset the field, this word only on my PC without GPIO enabled, but when the for event in pygame.event.get(): is added the program crash.
here a piece of my code:
Code: Select all
#Main loop
font = pygame.font.SysFont('none', 100)
run = True
while run:
GPIO.add_event_detect(38, GPIO.RISING, callback=Lane1, bouncetime=30)
GPIO.add_event_detect(40, GPIO.RISING, callback=Lane2, bouncetime=30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
Lane1()
if event.key == pygame.K_2:
Lane2()
if event.key == pygame.K_ESCAPE:
pygame.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
mx, my = pygame.mouse.get_pos()
print (mx, my)
if mx >10 and mx <233 and my >33 and my <100:
L1_OT = 66
if mx >245 and mx <463 and my >33 and my <100:
L2_OT = 77
if mx >10 and mx <233 and my >133 and my <200:
L1_HOT = 88
if mx >245 and mx <463 and my >133 and my <200:
L2_HOT = 99
if mx >10 and mx <233 and my >233 and my <300:
L1_KO = 0
if mx >245 and mx <463 and my >233 and my <300:
L2_KO = 0
redrawGameWindow()
GPIO.cleanup()
print("Done")
pygame.quit()