Advertisement
andrewb

microbit_di.py

Apr 28th, 2019
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from microbit import *
  2. import random
  3.  
  4. NUMBER_COUNT = 0
  5.  
  6. NUMBER_LIST = [
  7.     Image("70000:70000:70000:70000:70000"),
  8.     Image("77700:00700:77700:70000:77700"),
  9.     Image("77700:00700:77700:00700:77700"),
  10.     Image("70700:70700:77700:00700:00700"),
  11.     Image("77700:70000:77700:00700:77700"),
  12.     Image("77700:70000:77700:70700:77700"),
  13.     Image("77700:00700:00700:00700:00700"),
  14.     Image("77700:70700:77700:70700:77700"),
  15.     Image("77700:70700:77700:00700:77700"),
  16.     Image("70777:70707:70707:70707:70777"),
  17.     Image("70700:70700:70700:70700:70700"),
  18.     Image("70777:70007:70777:70700:70777"),
  19. ]
  20.  
  21. DI_NUMBER = len(NUMBER_LIST) - 1
  22.  
  23. DISPLAY_NUMBER = NUMBER_LIST[DI_NUMBER]
  24.  
  25. def change_di(di_number, incr_number):
  26.     sleep(250)
  27.     return di_number + incr_number
  28.  
  29. while True:
  30.     if accelerometer.was_gesture("shake"):
  31.         display.clear()
  32.         sleep(500)
  33.         random.seed()
  34.         random_roll = random.randint(0, DI_NUMBER)
  35.         DISPLAY_NUMBER = NUMBER_LIST[random_roll]
  36.     else:
  37.         if button_a.is_pressed() and DI_NUMBER > 1:
  38.             DI_NUMBER = change_di(DI_NUMBER, -1)
  39.             DISPLAY_NUMBER = NUMBER_LIST[DI_NUMBER]
  40.         if button_b.is_pressed() and DI_NUMBER < int(len(NUMBER_LIST) - 1):
  41.             DI_NUMBER = change_di(DI_NUMBER, 1)
  42.             DISPLAY_NUMBER = NUMBER_LIST[DI_NUMBER]
  43.  
  44.     display.show(DISPLAY_NUMBER)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement