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.
Thanks
Garry
Countdown timer that resets on "shake"
Re: Countdown timer that resets on "shake"
Hi,
Microsoft MakeCode has interrupts. Micropython on the micro:bit does not.
This works for me (using the mu-editor):
lujo
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:
display.show(count, delay=50)
count = count - 1
if count <= 0:
display.show(Image.ANGRY)
break
sleep(10)
if accelerometer.was_gesture('shake'):
display.show(Image.HAPPY, delay=1000, clear=True)
count = 100
Re: Countdown timer that resets on "shake"
Here's a response to a similar question that goes into this in more detail -- viewtopic.php?f=17&t=7150#p40706