Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Verbindet zwei micro:bits, die die Klicks des jeweils anderen zählen
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- import radio
- # Schalte Radio ein, und setze einige Parameter; siehe
- # https://microbit-micropython.readthedocs.io/en/v2-docs/radio.html#functions
- radio.on()
- radio.config(channel=) # gib hier den Kanal an (0-83)
- radio.config(power=3) # setze die Signal-Stärke (0-7)
- count = 0
- while True:
- # Taste A: erhöhe den Zähler des *anderen* micro:bits
- if microbit.button_a.is_pressed():
- radio.send(str(1))
- while microbit.button_a.is_pressed():
- pass
- # Taste B: setze meinen *eigenen* Zähler zurück
- if microbit.button_b.is_pressed():
- count = 0
- while microbit.button_b.is_pressed():
- pass
- # Erhöhe meinen Zähler, wenn eine Nachricht des *anderen* angekommen ist
- 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