radio receive

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
DPaul
Posts: 10
Joined: Tue Mar 05, 2019 3:47 pm

radio receive

Post by DPaul » Fri Feb 11, 2022 3:37 pm

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

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: radio receive

Post by karfas » Fri Feb 11, 2022 4:05 pm

An if statement.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: radio receive

Post by lujo » Fri Feb 11, 2022 5:38 pm

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

DPaul
Posts: 10
Joined: Tue Mar 05, 2019 3:47 pm

Re: radio receive

Post by DPaul » Fri Feb 11, 2022 6:20 pm

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

DPaul
Posts: 10
Joined: Tue Mar 05, 2019 3:47 pm

Re: radio receive

Post by DPaul » Sat Feb 12, 2022 6:42 am

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

Post Reply