MicroBit Egg Timer
The following project is a simple timer with an Hourglass animation executed on a Microbit.
The user sets a integer time between 1 and 9 which represents the total elapsed time in minutes.
The time can be stopped, restarted or reset with defined buttons.
When the elapsed time is reached a melody will be played and the display will switched off.
Downloads
Supplies
Microbit V1 or V2
On Start
Initialises variables, sets speaker mode = off V1 and on V2 & starting display.
Hourglass
The hourglass animation is a sequence of 10 images with and LED change per image to give the impression of falling sand from the top to the bottom.
Set Time Duration
Button A is used to set the time duration between 1 and 9 minutes.
Each time button A is pressed the time duration is increased by 1 up to a maximum of 9 then resets back to 1.
Dimming mode is disabled for this option.
Timer Stop/start
Button B starts or stops the time.
Press the button to start the timer and press the button to stop the timer.
When the button is pressed it displays the set time and the hourglass animation starts, cycling between full to empty until the time duration is met at which point it stops and then dims.
If V1 then no melody is heard unless an external speaker is connected between P0 and GND. Ensure speaker mode set to OFF.
If V2 then a melody is played from the internal speaker if the speaker mode is set to ON.
When pressed again the process stops and the display is dimmed after ~ 6 seconds.
Reset
Pressing both A & B buttons together resets the variables and displays RST.
Timeout is set to aero.
Pressing button B at this stage can be used to test the melody.
Dimming
This is used to dim the display after 255 * 25 ms = ~6.4 seconds.
Z decremented each iteration from 255 [full brightness] to 0 [off] which controls the display brightness, if Y is set to True.
Forever
Main body of code with an infinite loop.
Initiate timer if Start=true and elasped minutes < then timeout
Pause is to enable fine time adjustment. Default = 0
Seconds time is derived from loop execution time with is governed more by the display animation updates.
1 minute = (60 / ((image time [500mS] + Pause [mS]) * images [10])) = 12 loops.
Pause is to enable fine adjustment of timer.
Display is updated each loop [sandsoftime]
Timer terminated when elapsed time [minutes] = set time [timeout]
Dimming function applied to save power and blank display.
Operation
Switch on.
The primed hourglass will be shown.
Press button A repeatedly to set the time from 1 to 9 minutes.
The time selected will be updated and shown on the display.
Press button B to start the timer.
The animation will play showing the sands of time falling until the bottom is full at which point it repeats until the time has elapsed, then it stops and fades away.
Depending upon the version the following options will exist.
If using V1 you will need to fit an external speaker to hear the melody.
If using V2 the melody will be produced by the internal speaker.
Pressing button B during the timing process stops the timer and pressing against restarts it.
The timer is reset by pressing both A & B buttons together.
Downloads
Finally
Thanks for viewing and hope you found it interesting.