Advertisement
rric

jeder_scrollt_mit

Feb 6th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. # Dieser micro:bit wird Teil einer "Nachrichten-Kette": Nachrichten werden
  2. # auf einem Kanal empfangen, angezeigt und im nächsten Kanal weiter gesendet.
  3. # Diese Version verwendet einen scroll:bit; dazu muss scrollbit.py am micro:bit
  4. # installiert sein, siehe https://github.com/pimoroni/micropython-scrollbit
  5. # Copyright 2023, 2024 Roland Richter                [Mu: BBC micro:bit]
  6.  
  7. import microbit
  8. import scrollbit
  9. import radio
  10.  
  11. def set_my_channel():
  12.     global my_channel
  13.     microbit.display.show(str(my_channel))
  14.     radio.config(channel=my_channel)
  15.  
  16. my_channel = 0
  17. radio.on()
  18. set_my_channel()
  19.  
  20. while True:
  21.     if microbit.button_a.is_pressed():
  22.         my_channel = 0
  23.         set_my_channel()
  24.         while microbit.button_a.is_pressed():
  25.             pass
  26.  
  27.     elif microbit.button_b.is_pressed():
  28.         my_channel += 1
  29.         set_my_channel()
  30.         while microbit.button_b.is_pressed():
  31.             pass
  32.  
  33.     incoming = radio.receive()
  34.     if incoming is not None:
  35.         scrollbit.scroll(str(incoming))
  36.         neighbour = my_channel + 1
  37.         radio.config(channel=neighbour)
  38.         radio.config(power=3)
  39.         radio.send(str(incoming))
  40.         radio.config(channel=my_channel)
  41.  
  42. # ----------------------------------------------------------------------
  43. # This program is free software: you can redistribute it and/or modify
  44. # it under the terms of the GNU General Public License as published by
  45. # the Free Software Foundation, either version 3 of the License, or
  46. # (at your option) any later version.
  47. #
  48. # This program is distributed in the hope that it will be useful,
  49. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  50. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  51. # GNU General Public License for more details.
  52. #
  53. # You should have received a copy of the GNU General Public License
  54. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement