Microsoft MakeCode

Microbit ignoring radio message when in "while" loop

Hi. I have a program where one microbit board is blinking (dim up / down) some neopixel led’s. It should leave the “while” loop when its radio module receives a certain message, thus setting the “Rx_side_valg” to eigher “1” or “2”. The “while” loop condition should no longer be present and the program should leave the loop.

However the program stays in the loop and completely ignores the radio input,and just keeps on fading the led’s up and down.

But if it receives the message BEFORE the “while” loop, it jumps over the loop and continues on.

So BEFORE the loop it listens to the incoming radio signals, but completely ignores them in the loop. I have tried changing the delays to 1000us, but still it gets stuck in the loop.

How can I force it to listen to the radio even when it is in the loop?

Hi wolfman,

Try using a basic.pause instead of a wait. The pause allows the micro:bit scheduler to check for any events whereas I believe the waitMicros will only check if you sleep longer than 50000 us. You can see this in scheduler.cpp:

There you see that when you use the basic.pause( which calls sleep_ms), it will call the scheduler. If you use waitMicros, it calls the sleep_us and will internally call the sleep_ms if us >50000.

So in short, try using basic.pause instead to allow the scheduler to check for radio events.

1 Like

Thank you thank you thank you, joshkeys19.

That did it. Now the board listens for possible incoming radio message.

I just thought that it was a time factor difference. Did not know that the board reacted in different ways to it.

Problem seems solved.

You’re welcome! Glad I could help. :slight_smile:

Oh you help alot there.

Mind if I ask for another help?

I am using a second board as a “remote” that sends messages to this first board.

However it remembers if button “A” (example) has been pressed twice, perhaps by mistake.

Is there a way to make the board ignore any buttons pressed for a period of a second or two? I have not been able to find any information on disabling and re-enabling the buttons on the board itself.

Hi Wolfman,

It sounds like you want a bit of a denouncer enabled. An easy way would be to implement a software denouncer.

Your code would be where the hearts are. Every time the button A is pressed, it first checks to see if at least 2000mS have passed since the last time it was pressed.

I hope that helps.

Thanks,
Josh

Once again - Thank you.

I will try implementing a debouncer function.