# Morse code messenger: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/morse-messenger
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# Morse code messenger: A sends a dot, B sends a dash, and the other board shows and sounds it.
from microbit import *
import radio
import music

radio.on()
radio.config(group=3)
DOT = Image("00000:00000:00900:00000:00000")
DASH = Image("00000:00000:09990:00000:00000")

while True:
    if button_a.was_pressed():
        radio.send(".")
    if button_b.was_pressed():
        radio.send("-")
    message = radio.receive()
    if message == ".":
        display.show(DOT)
        music.pitch(330, 150)
        display.clear()
    elif message == "-":
        display.show(DASH)
        music.pitch(330, 450)
        display.clear()
    sleep(20)
