I have a bit of a head scratcher here, my wife was working on this code for her micro:bit. The idea behind the program is to have an alarm system to alert you if a young child opened a door. Pressing “A” will arm the alarm system. Pressing “B” will disarm the system. We have a forever loop to run to check if the alarm has been shaken (door opening) and that will then play a sound and update the LED screen.
In the simulator, everything works as expected, pressing the “A” button arms the device, shaking the device sets off the alarm. Pressing the “B” button disarms the device. When we try the same thing on the actual micro:bit however, the alarm sound and updated LED screen only fires once. We originally only had an if statement instead of the do while loop that is in the current code. Is this a bug with the device itself? I wasn’t sure why the simulator itself gave us one result, and the micro:bit gave us a completely different result.
Code here: https://makecode.microbit.org/67614-77750-93851-58307
Hm, I just downloaded it from the share link and it worked on the micro:bits I had off hand – could you check on two things for me:
- the micro:bit hardware version (if it’s a micro:bit v1 that should be enough, otherwise if it’s a v2 micro:bit there should be a very tiny version number on the back to the right of the micro:bit insignia / logo)
- the firmware version – there are details here https://microbit.org/get-started/user-guide/firmware/ but you just want to look at the DETAILS file that is on the micro:bit and get the listed ‘Interface Version’
I feel like I vaguely remember there being some firmware issue with the shake gesture in the past but I’m not fully certain, I’ll look around in the meantime
edit: the ones that came to mind were https://github.com/microsoft/pxt-microbit/issues/2234 – if it still doesn’t work after updating firmware could you try
and see if that works as expected? It’s a small tweak to yours where it uses the event instead of a loop to check – if one works and the other doesn’t that would be helpful to know in diagnosing the issue