MicroBit Egg Timer

by Gammawave in Circuits > Microcontrollers

1160 Views, 2 Favorites, 0 Comments

MicroBit Egg Timer

hourglass.png
microbit-egg_timer3.png

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.

Supplies

Microbit V1 or V2

Makecode

On Start

onstart.png
hourglass.png

Initialises variables, sets speaker mode = off V1 and on V2 & starting display.

Hourglass

sandsoftime.png

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

buttona.png
one.png
nine.png

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

buttonb.png
stop.png

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

buttonab.png

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

dimming.png

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

forever.png
start.png
time_interval.png

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

start.png

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.