Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Verwende deinen micro:bit als einfache Stoppuhr
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- microbit.display.show(microbit.Image.DIAMOND_SMALL)
- # "pass" bedeutet "tue nichts"; hier: tue solange nichts, bis A gedrückt wird
- while not microbit.button_a.is_pressed():
- pass
- # Speichere die Start-Zeit (in Millisekunden)
- start_time = microbit.running_time()
- while not microbit.button_b.is_pressed():
- # Berechne die letzten drei Stellen der abgelaufenen Zeit, z.B.
- # 917 ms -> 917
- # 2451 ms -> 451
- # 8056 ms -> 56
- # 10189 ms -> 189
- last_digits = (microbit.running_time() - start_time) % 1000
- if last_digits < 250:
- microbit.display.show(microbit.Image.CLOCK12)
- elif last_digits < 500:
- microbit.display.show(microbit.Image.CLOCK3)
- # PROBIERE diese "wenn-dann-sonst" Verzweigung fertig zu stellen
- # Speichere die Stopp-Zeit (in Millisekunden)
- stop_time = microbit.running_time()
- # Zeige die Zeit zwischen Start und Stopp (in Millisekunden)
- elapsed = stop_time - start_time
- microbit.display.scroll(str(elapsed) + " ms")
- # PROBIERE, die Zeit in Sekunden (statt Millisekunden) anzuzeigen.
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment