Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Turns two micro:bits into two "counterparts", counting clicks of each other
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- import radio
- radio.on()
- radio.config(channel=) # set your channel here
- radio.config(power=3)
- count = 0
- while True:
- # button A: increment my *counterparts* count
- if microbit.button_a.is_pressed():
- radio.send(str(1))
- while microbit.button_a.is_pressed():
- pass
- # button B: reset my *own* count
- if microbit.button_b.is_pressed():
- count = 0
- while microbit.button_b.is_pressed():
- pass
- # increment my own count if my *counterpart* sent a message
- incoming = radio.receive()
- if incoming is not None:
- if int(incoming) == 1:
- count += 1
- microbit.display.show(str(count))
- microbit.sleep(100)
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement