Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- filename:gpio_rpi_python_steady.py
- Steady! game code for rpi
- written by Trevor Olsson
- © GPIO Support Services LTD MMXVII
- more info at www.gpio.co.uk/steady
- """
- from gpiozero import Button, LED, Motor, Buzzer
- import time
- import os
- btnD=Button(25,pull_up=False)# press to start game
- Main_Section = Button(14,pull_up = False) # touch 3 times to lose
- End_Section = Button(4,pull_up=False) # Touch to win
- bz=Buzzer(24)
- Mtr = Motor(27,22)
- Lights = LED(23)
- Lives=3
- print("Press Button D to Start")
- btnD.wait_for_press()
- print ("Game Running")
- while True:
- if Lives==0:
- print ("Game Lost")
- break
- if End_Section.is_pressed:
- os.system('omxplayer Heart.mp3 &')
- print ("Game Won - Well Done")
- Mtr.forward()
- Lights.on()
- time.sleep(25)
- Mtr.stop()
- Lights.off()
- break
- if Main_Section.is_pressed:
- print (Lives)
- bz.on()
- time.sleep(1)
- bz.off()
- Lives=Lives-1
Advertisement
Add Comment
Please, Sign In to add comment