Advertisement
rric

hier_und_dort

Feb 5th, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # Verbindet zwei micro:bits, die die Klicks des jeweils anderen zählen
  2. # Copyright 2023, 2024 Roland Richter                [Mu: BBC micro:bit]
  3.  
  4. import microbit
  5. import radio
  6.  
  7. # Schalte Radio ein, und setze einige Parameter; siehe
  8. # https://microbit-micropython.readthedocs.io/en/v2-docs/radio.html#functions
  9. radio.on()
  10. radio.config(channel=)  # gib hier den Kanal an (0-83)
  11. radio.config(power=3)   # setze die Signal-Stärke (0-7)
  12.  
  13. count = 0
  14.  
  15. while True:
  16.     # Taste A: erhöhe den Zähler des *anderen* micro:bits
  17.     if microbit.button_a.is_pressed():
  18.         radio.send(str(1))
  19.         while microbit.button_a.is_pressed():
  20.             pass
  21.  
  22.     # Taste B: setze meinen *eigenen* Zähler zurück
  23.     if microbit.button_b.is_pressed():
  24.         count = 0
  25.         while microbit.button_b.is_pressed():
  26.             pass
  27.  
  28.     # Erhöhe meinen Zähler, wenn eine Nachricht des *anderen* angekommen ist
  29.     incoming = radio.receive()
  30.  
  31.     if incoming is not None:
  32.         if int(incoming) == 1:
  33.             count += 1
  34.  
  35.     microbit.display.show(str(count))
  36.     microbit.sleep(100)
  37.  
  38. # ----------------------------------------------------------------------
  39. # This program is free software: you can redistribute it and/or modify
  40. # it under the terms of the GNU General Public License as published by
  41. # the Free Software Foundation, either version 3 of the License, or
  42. # (at your option) any later version.
  43. #
  44. # This program is distributed in the hope that it will be useful,
  45. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  47. # GNU General Public License for more details.
  48. #
  49. # You should have received a copy of the GNU General Public License
  50. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement