Morse1 Lösung

Aus microbit - Das Schulbuch
Wechseln zu: Navigation, Suche

Detailschritte

  • Anzeige eines einzelnen Morsesymbols:

input.onButtonPressed(Button.A, function () {
    basic.showLeds(`
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        `)
    basic.showLeds(`
        . . . . .
        . . . . .
        . . # . .
        . . . . .
        . . . . .
        `)
})
input.onButtonPressed(Button.B, function () {
    basic.showLeds(`
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        `)
    basic.showString("-")
})
basic.showLeds(`
    . . # . .
    # # # # #
    . . # . .
    . # . # .
    # . . . #
    `)


  • Verbindung von 2 Micro:bits:
input.onButtonPressed(Button.A, function () {
    basic.showString("Hello!")
})
radio.onReceivedString(function (receivedString) {
    basic.showString(receivedString)
})
radio.setGroup(25)


  • Senden von Nachrichten:

Beide micro:bit können bei diesem Beispiel denselben Programmcode verwenden.

input.onButtonPressed(Button.A, function () {
    radio.sendString("Hallo")
})
radio.onReceivedString(function (receivedString) {
    basic.showString(receivedString)
})
radio.setGroup(25)


  • Senden von Morsecode:

Beide micro:bit können bei diesem Beispiel denselben Programmcode verwenden.

input.onButtonPressed(Button.A, function () {
    radio.sendString(".")
})
radio.onReceivedString(function (receivedString) {
    basic.showString(receivedString)
})
input.onButtonPressed(Button.B, function () {
    radio.sendString("-")
})
radio.setGroup(25)
  • Empfangen von Morsecode mit Soundausgabe:

Beide micro:bit können bei diesem Beispiel denselben Programmcode verwenden.

radio.onReceivedString(function (receivedString) {
    if (receivedString.includes(".")) {
        music.playTone(262, music.beat(BeatFraction.Whole))
        basic.showLeds(`
            . . . . .
            . . . . .
            . . # . .
            . . . . .
            . . . . .
            `)
    } else {
        music.playTone(262, music.beat(BeatFraction.Breve))
        basic.showString("-")
    }
})


Zurück zur Aufgabe