Advertisement
gPiOBox

Further - Steady! game code for micro:bit

Oct 17th, 2017
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. """
  2. filename:gpio_mb_python_steady.py
  3. Steady! game code for micro:bit
  4. written by Trevor Olsson
  5. © GPIO Support Services LTD MMXVII
  6. more info at www.gpio.co.uk/steady
  7. """
  8. from microbit import *
  9. Lives=3
  10. display.show(str(Lives))
  11. while True:
  12.     if button_a.is_pressed(): # Touch this to win
  13.         display.show(Image.HAPPY)
  14.         pin16.write_digital(1)
  15.         pin13.write_digital(1)
  16.         sleep(5000)
  17.         pin16.write_digital(0)
  18.         pin13.write_digital(0)
  19.         break
  20.     else:
  21.         if button_b.is_pressed(): # Touch this 3 times to lose
  22.             if Lives==1:
  23.                 pin15.write_digital(1)
  24.                 sleep(2000)
  25.                 pin15.write_digital(0)
  26.                 display.scroll("Game Lost")
  27.                 break
  28.             else:
  29.                 Lives=Lives-1
  30.                 display.show(str(Lives))
  31.                 pin15.write_digital(1)
  32.                 sleep(1000)
  33.                 pin15.write_digital(0)
  34. display.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement