rric

chronometer

Jan 16th, 2024 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. # Verwende deinen micro:bit als einfache Stoppuhr
  2. # Copyright 2023, 2024 Roland Richter                [Mu: BBC micro:bit]
  3.  
  4. import microbit
  5.  
  6. microbit.display.show(microbit.Image.DIAMOND_SMALL)
  7.  
  8. # "pass" bedeutet "tue nichts"; hier: tue solange nichts, bis A gedrückt wird
  9. while not microbit.button_a.is_pressed():
  10.     pass
  11.  
  12. # Speichere die Start-Zeit (in Millisekunden)
  13. start_time = microbit.running_time()
  14.  
  15. while not microbit.button_b.is_pressed():
  16.     # Berechne die letzten drei Stellen der abgelaufenen Zeit, z.B.
  17.     #   917 ms -> 917
  18.     #  2451 ms -> 451
  19.     #  8056 ms ->  56
  20.     # 10189 ms -> 189
  21.     last_digits = (microbit.running_time() - start_time) % 1000
  22.  
  23.     if last_digits < 250:
  24.         microbit.display.show(microbit.Image.CLOCK12)
  25.     elif last_digits < 500:
  26.         microbit.display.show(microbit.Image.CLOCK3)
  27.     # PROBIERE diese "wenn-dann-sonst" Verzweigung fertig zu stellen
  28.  
  29. # Speichere die Stopp-Zeit (in Millisekunden)
  30. stop_time = microbit.running_time()
  31.  
  32. # Zeige die Zeit zwischen Start und Stopp (in Millisekunden)
  33. elapsed = stop_time - start_time
  34. microbit.display.scroll(str(elapsed) + " ms")
  35.  
  36. # PROBIERE, die Zeit in Sekunden (statt Millisekunden) anzuzeigen.
  37.  
  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