Morse1 Lösung: Unterschied zwischen den Versionen

Aus microbit - Das Schulbuch
Wechseln zu: Navigation, Suche
(Detailschritte)
 
Zeile 103: Zeile 103:
 
</pre>
 
</pre>
  
* Eine mögliche [https://makecode.microbit.org/#pub:_0g9dXKhwH4Ap Lösung]:
+
* Eine mögliche [https://makecode.microbit.org/#pub:_RC3ibRdvT83C Lösung]:
 +
 
  
 
[[morse1|Zurück zur Aufgabe]]
 
[[morse1|Zurück zur Aufgabe]]

Aktuelle Version vom 7. März 2022, 13:52 Uhr

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