gPiOBox

Further - Steady! game code for Raspberry Pi

Oct 17th, 2017
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. """
  2. filename:gpio_rpi_python_steady.py
  3. Steady! game code for rpi
  4. written by Trevor Olsson
  5. © GPIO Support Services LTD MMXVII
  6. more info at www.gpio.co.uk/steady
  7. """
  8. from gpiozero import Button, LED, Motor, Buzzer
  9. import time
  10. import os
  11.  
  12. btnD=Button(25,pull_up=False)# press to start game
  13. Main_Section = Button(14,pull_up = False) # touch 3 times to lose
  14. End_Section = Button(4,pull_up=False) # Touch to win
  15. bz=Buzzer(24)
  16. Mtr = Motor(27,22)
  17. Lights = LED(23)
  18.  
  19. Lives=3
  20. print("Press Button D to Start")
  21. btnD.wait_for_press()
  22. print ("Game Running")
  23.  
  24. while True:
  25.     if Lives==0:
  26.                 print ("Game Lost")
  27.                 break
  28.     if End_Section.is_pressed:
  29.         os.system('omxplayer Heart.mp3 &')
  30.         print ("Game Won - Well Done")
  31.         Mtr.forward()
  32.         Lights.on()
  33.         time.sleep(25)
  34.         Mtr.stop()
  35.         Lights.off()
  36.         break
  37.     if Main_Section.is_pressed:
  38.         print (Lives)
  39.         bz.on()
  40.         time.sleep(1)
  41.         bz.off()
  42.         Lives=Lives-1
Advertisement
Add Comment
Please, Sign In to add comment