micro:bit MicroPython: Getting the device running time
DFRobot
Apr 08 2019855
In this microbit tutorial we will check how to get the running time of the micro:bit, since the board was turned on or restarted.
Introduction
In this tutorial we will check how to get the running time of the micro:bit, since the board was turned on or restarted.
In order to get this value, we will use a function from the microbit module. The function we will use is called running_time.
The code
The code for this tutorial will be really simple and short, as we will see below. First, we will start by importing the microbit module which, as already mentioned, contains the function we need to get the running time.
import microbit
Then, to obtain the running time, we simply need to call the running_time function. This function takes no arguments and returns the device running time, in milliseconds [1].
We can directly print the value returned by the running_time function, as shown below.
print(running_time())
The complete code can be seen below.
import microbit
print(running_time())
Testing the code
To test the code, simply run it on your micro:bit board using a tool of your choice. In my case, I’ll be using uPyCraft, a MicroPython IDE.
You should get an output similar to figure 1. As can be seen, the number of milliseconds elapsed since my device started was printed to the MicroPython console. Naturally, your values will most likely differ from mine, depending on the time that has passed between your device start and running the command.
Explore the performance of Small Language Models (SLMs) on the Raspberry Pi 5 SBC, including models like mathstral, phi 3, llama 3.1, gemma2 2b, and Qwen.
Explore our top picks for interactive sensors, DIY lighting, essential maker tools, and exciting project ideas to make this Halloween truly unforgettable!
This blog will provide an in-depth comparison of YOLOv10 and YOLOv8, analyzing their differences in model size, performance metrics, and hardware requirements.