STEAM DISCOVERY LAB
  • About
  • Tools
  • Projects
  • Resources
  • About
  • Tools
  • Projects
  • Resources
Search

Micro:Bit Stop Watch

Picture

​Lesson Objectives:
  1. Students will learn about while loops​
  2. Students will learn to use micro-controllers

Materials:
  • BBC micro:bit
  • Laptop with Mu Software 
​
​Goal:
Create a stopwatch with a micro:bit that records how long a button is pressed and displays the result. 

You will want to make use of the micro:bit function called microbit.running_time() which returns the number of milliseconds since the micro:bit started running.

Features:
  1. While button A is pressed, the stopwatch should continually update the elapsed time.
  2. LED "timing" Indicator on the micro:bit's screen while the button is pressed to tell you that the stopwatch is "running". 
  3. When button A is released the stopwatch should display the elapsed time on the LED display.
  4. After the time elapsed is displayed, the stopwatch should reset and loop back to be ready for timing something else. 

Challenge: Use an animated and accurate analog clock face as the indicator
Micro:bit includes images of clocks in the microbit library. In fact, there is even a list of clock faces Image.ALL_CLOCKS[clock_num] where you replace clock number with the "hour" that you want the clock to point to, integers 1 through 12. Use this to animate a clocks second hand that points to 1 o'clock after 5 seconds (5000 ms) have elapsed (and up to 10 seconds), 2 o'clock after 10 seconds (and up to 15), etc. After a full minute, your animation should loop back around like a real stopwatch. For example, 1 minute and 15 seconds should be pointing at 3 o'clock.
Code
Step 1 Code

    
References
The following functions (documentation copied from microBit microPython) documentation may be helpful. The Image and Display classes are also relevant.

The full documentation may be found here:
  • https://microbit-micropython.readthedocs.io/en/latest/microbit_micropython_api.html

is_pressed()
Returns True if the specified button button is currently being held down, and False otherwise.
​
microbit.display.show(image)
Display the image.
​
microbit.display.scroll(value, delay=150, *, wait=True, loop=False, monospace=False)
Scrolls value horizontally on the display. If value is an integer or float it is first converted to a string using str(). The delay parameter controls how fast the text is scrolling.
If wait is True, this function will block until the animation is finished, otherwise the animation will happen in the background.
If loop is True, the animation will repeat forever.
If monospace is True, the characters will all take up 5 pixel-columns in width, otherwise there will be exactly 1 blank pixel-column between each character as they scroll.
Note that the wait, loop and monospace arguments must be specified using their keyword.
Picture
200 Boston Ave, Medford, MA 02155
steamdiscoverylab@gmail.com
Center for Engineering Education and Outreach
​Tufts University
About
Tools
Projects
Resources
​
Contact
LEGO®, the LEGO® logo, the Brick, MINDSTORMS®, and the Minifigure are trademarks of ©The LEGO® Group. On some parts of this site  you will get access to so-called “developer software”, which offers documentation on different ways to operate the LEGO® Education SPIKE™ Prime Hub and technology. Whatever use you make of the developer software, bear in mind that the results are not experiences that the LEGO Group endorses, is with or will be liable for. No rights in or to trademarks of the LEGO Group are implied or given, and you may not apply to or register any protection anywhere in the world for intellectual property or industrial rights or similar in respect of any developer software, derivative or other result achieved through its use. The developer software is made available “as is” and, to the extent possible, no warranties or representations are implied or given in relation to it by the LEGO Group. It’s your responsibility to ensure all uses that you make and enable others to make comply with all applicable laws and best practices. By accessing the developer software, you acknowledge that the terms and conditions set out above and in LEGO Education’s terms of use for SPIKE Prime apply.
  • About
  • Tools
  • Projects
  • Resources