Page 1 of 1

radio receive

Posted: Fri Feb 11, 2022 3:37 pm
by DPaul
Hi,
I have a setup with 1 micro:bit that (radio) receives data, and 10 other that send data (yes/no votes).
I need to receive the sender's data only when the reception function is "open".
Outside this window any data sent should be disregarded.
What would be the best approach to disregard any sent messages, without switching off power
on the receiving side.
thx,
Paul

Re: radio receive

Posted: Fri Feb 11, 2022 4:05 pm
by karfas
An if statement.

Re: radio receive

Posted: Fri Feb 11, 2022 5:38 pm
by lujo
Hi,

Code: Select all

run = False

while True:
    if button_a.was_pressed():
        run = not run
        
    if run:
        data = radio.receive()
        if data:
            ...
hth,
lujo

Re: radio receive

Posted: Fri Feb 11, 2022 6:20 pm
by DPaul
Thanks Lujo, good idea ;
Of course, i need to switch it on and off again: button_a twice
(I'm in luck, buttons are free from other functions, so it might work.)
To show the status, we could show an Image.
Dpaul

Re: radio receive

Posted: Sat Feb 12, 2022 6:42 am
by DPaul
After giving it some thought, I wonder why the kiss solution
was not proposed. If I can do radio.on(), there must be a radio.off().
No need for extra variables, no nested if statements.
Two Images to reflect the status. Done.
Dpaul