Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Turns your micro:bit into a very simple stopwatch
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- microbit.display.show(microbit.Image.DIAMOND_SMALL)
- # "pass" means "do nothing"; here, do nothing in a loop until A is pressed
- while not microbit.button_a.is_pressed():
- pass
- # set the start time (in milliseconds)
- start_time = microbit.running_time()
- while not microbit.button_b.is_pressed():
- # calculate the last three digits of the time elapsed, e.g.
- # 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)
- # TRY to complete this "if-then-else" statement to show a rotating clock hand
- # set the stop time (in milliseconds)
- stop_time = microbit.running_time()
- # show the elapsed time (in milliseconds)
- elapsed = stop_time - start_time
- microbit.display.scroll(str(elapsed) + " ms")
- # TRY to show the elapsed time in seconds, instead of milliseconds.
- # ----------------------------------------------------------------------
- # 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
Advertisement