mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Convert recipe examples to includes
Makes it much easier to test things - no copying'n'pasting just run the examples straight from the dir (after wiring stuff up)
This commit is contained in:
22
docs/examples/reaction_game.py
Normal file
22
docs/examples/reaction_game.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from gpiozero import Button, LED
|
||||
from time import sleep
|
||||
import random
|
||||
|
||||
led = LED(17)
|
||||
|
||||
player_1 = Button(2)
|
||||
player_2 = Button(3)
|
||||
|
||||
time = random.uniform(5, 10)
|
||||
sleep(time)
|
||||
led.on()
|
||||
|
||||
while True:
|
||||
if player_1.is_pressed:
|
||||
print("Player 1 wins!")
|
||||
break
|
||||
if player_2.is_pressed:
|
||||
print("Player 2 wins!")
|
||||
break
|
||||
|
||||
led.off()
|
||||
Reference in New Issue
Block a user