rric

expert_clicker

Feb 5th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. # Verwandelt den micro:bit in einen "Klicker", um Tasten-Klicks zu zählen
  2. # Copyright 2023, 2024 Roland Richter                [Mu: BBC micro:bit]
  3.  
  4. import microbit
  5.  
  6. count = 0
  7.  
  8. while True:
  9.     microbit.display.show("?")
  10.  
  11.     # Warte, bis Taste A gedrückt wird ...
  12.     while not microbit.button_a.is_pressed():
  13.         pass
  14.  
  15.     # "+=" bedeutet "addiere die rechte Seite zur Variablen auf der linken Seite"
  16.     count += 1
  17.  
  18.     # "%" ist der modulo-Operator und berechnet den Rest einer Division.
  19.     # micro:bits können nur eine Ziffer anzeigen; zeige daher hier die Einer-Stelle an.
  20.     microbit.display.show(str(count % 10))
  21.  
  22.     # Warte, bis Taste A nicht mehr gedrückt ist ...
  23.     while microbit.button_a.is_pressed():
  24.         pass
  25.  
  26.     # PROBIERE den Zähler anzuzeigen, wenn die Taste B gedrückt wird.
  27.  
  28. # ----------------------------------------------------------------------
  29. # This program is free software: you can redistribute it and/or modify
  30. # it under the terms of the GNU General Public License as published by
  31. # the Free Software Foundation, either version 3 of the License, or
  32. # (at your option) any later version.
  33. #
  34. # This program is distributed in the hope that it will be useful,
  35. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  37. # GNU General Public License for more details.
  38. #
  39. # You should have received a copy of the GNU General Public License
  40. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  41.  
Advertisement
Add Comment
Please, Sign In to add comment