mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	Makes it much easier to test things - no copying'n'pasting just run the examples straight from the dir (after wiring stuff up)
		
			
				
	
	
		
			23 lines
		
	
	
		
			351 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			351 B
		
	
	
	
		
			Python
		
	
	
	
	
	
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()
 |