rric

digitaler_würfel

Jan 23rd, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. # Wirf einen Würfel? Nein, nur eine Münze ...
  2. # Copyright 2023, 2024 Roland Richter                [Mu: BBC micro:bit]
  3.  
  4. import microbit
  5. import random
  6.  
  7. while True:
  8.     # Als ich hier is_gesture() verwendet habe, hat einmal Schütteln mehrere
  9.     # "Münzwürfe" ausgelöst (d.h. Gesten werden zwischengespeichert); mit
  10.     # was_gesture() wird nur ein "Münzwurf" ausgelöst.
  11.     while not microbit.accelerometer.was_gesture("shake"):
  12.         pass
  13.        
  14.     # PROBIERE, welche Gesten hier noch Sinn machen.
  15.  
  16.     # Zeige fünf Mal Kopf und Zahl -- als würde die Münze sich drehen.
  17.     for k in range(5):
  18.         microbit.display.show(microbit.Image.HAPPY)
  19.         microbit.sleep(300)
  20.         microbit.display.show("1")
  21.         microbit.sleep(300)
  22.  
  23.     microbit.display.clear()
  24.     microbit.sleep(500)
  25.  
  26.     # Erzeuge eine zufällige ganze Zahl zwischen 1 und 2: also 1 oder 2 ...
  27.     randomvalue = random.randint(1, 2)
  28.  
  29.     # ... und zeige entweder "Kopf" 🙂 oder "Zahl" ① an.
  30.     if randomvalue == 1:
  31.         microbit.display.show(microbit.Image.HAPPY)
  32.     else:
  33.         microbit.display.show("1")
  34.  
  35.     microbit.sleep(1000)
  36.  
  37.     # PROBIERE, statt einer Münze einen Würfel ⚀,⚁,⚂,⚃,⚄,⚅ anzuzeigen.
  38.  
  39. # ----------------------------------------------------------------------
  40. # This program is free software: you can redistribute it and/or modify
  41. # it under the terms of the GNU General Public License as published by
  42. # the Free Software Foundation, either version 3 of the License, or
  43. # (at your option) any later version.
  44. #
  45. # This program is distributed in the hope that it will be useful,
  46. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  48. # GNU General Public License for more details.
  49. #
  50. # You should have received a copy of the GNU General Public License
  51. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  52.  
Advertisement
Add Comment
Please, Sign In to add comment