Countdown timer that resets on "shake"

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Posts: 1
Joined: Sun Nov 17, 2019 11:34 am

Countdown timer that resets on "shake"

Post by garrygorman » Sun Nov 17, 2019 12:25 pm

Hi all,
I have created a program using blocks that counts down from 100 and sounds an alarm on zero. The timer resets to 100 on "shake". I need to do this in micropython but I am having difficulty running the countdown timer and the shake function at the same time. Any help would be greatly appreciated.



Posts: 16
Joined: Sat May 11, 2019 2:30 pm

Re: Countdown timer that resets on "shake"

Post by lujo » Mon Nov 18, 2019 12:48 am


Microsoft MakeCode has interrupts. Micropython on the micro:bit does not.

This works for me (using the mu-editor):

Code: Select all

from microbit import *

count = 100
while True:, delay=50)
    count = count - 1
    if count <= 0:
    if accelerometer.was_gesture('shake'):, delay=1000, clear=True)
        count = 100

User avatar
Posts: 1681
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Countdown timer that resets on "shake"

Post by jimmo » Mon Nov 18, 2019 1:21 am

Here's a response to a similar question that goes into this in more detail -- viewtopic.php?f=17&t=7150#p40706

Post Reply