Guest User

Untitled

a guest
Feb 13th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. from microbit import *
  2. import math
  3. import random
  4.  
  5. # Kitronik INVENTOR'S KIT FOR BBC micro:bit p. 44-47
  6. # parts used: red 5mm led, 47ohm resistor, male-to-female jumper wire x 2
  7.  
  8. goal = 0
  9. difference = 0
  10. image = 0
  11. degrees = 0
  12.  
  13. compass.calibrate()
  14.  
  15. while True:
  16. degrees = compass.heading()
  17. difference = math.fabs(goal - degrees)
  18. pin0.write_digital(1)
  19. sleep(difference * 5)
  20. if(button_a.is_pressed()):
  21. if(difference < 15):
  22. display.scroll("Winner")
  23. goal = random.randint(0,360)
  24. else:
  25. display.scroll("Try again")
  26. goal = random.randint(0,360)
  27.  
  28. img = Image("09090:"
  29. "09090:"
  30. "00000:"
  31. "90009:"
  32. "09990")
  33. display.show(img)
  34. goal = random.randint(360)
Add Comment
Please, Sign In to add comment