Last active
January 16, 2024 03:03
-
-
Save Logabe/92d92b8303d20a1603ea7a9d419652c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a piece of code my friend and I wrote for the Micro:Bit which turns it into a Morse-Code-based pager. | |
Button A sends '.', Button B sends '-', and pressing the two together sends a space. | |
The Micro:Bit can then be shaken to send the character. */ | |
enum RadioMessage { | |
message1 = 49434 | |
} | |
input.onButtonPressed(Button.A, function () { | |
CharacterToDecode = "" + CharacterToDecode + "." | |
}) | |
input.onButtonPressed(Button.B, function () { | |
CharacterToDecode = "" + CharacterToDecode + "-" | |
}) | |
input.onButtonPressed(Button.AB, function () { | |
radio.sendString(" ") | |
CharacterToDecode = "" | |
}) | |
radio.onReceivedString(function (receivedString) { | |
basic.clearScreen() | |
basic.showString(receivedString) | |
}) | |
input.onGesture(Gesture.Shake, function () { | |
if (!(CharacterToDecode.isEmpty())) { | |
radio.sendString("" + (alphabet[morse.indexOf(CharacterToDecode)])) | |
CharacterToDecode = "" | |
} | |
CharacterToDecode = "" | |
}) | |
let alphabet: string[] = [] | |
let morse: string[] = [] | |
let CharacterToDecode = "" | |
radio.setTransmitPower(7) | |
radio.setFrequencyBand(1) | |
CharacterToDecode = "" | |
morse = [ | |
".-", | |
"-...", | |
"-.-.", | |
"-..", | |
".", | |
"..-.", | |
"--.", | |
"....", | |
"..", | |
".---", | |
"-.-", | |
".-..", | |
"--", | |
"-.", | |
"---", | |
".--.", | |
"--.-", | |
".-.", | |
"...", | |
"-", | |
"..-", | |
"...-", | |
".--", | |
"-..-", | |
"-.--", | |
"--..", | |
".----", | |
"..---", | |
"...--", | |
"....-", | |
".....", | |
"-....", | |
"--...", | |
"---..", | |
"----.", | |
"-----" | |
] | |
alphabet = [ | |
"A", | |
"B", | |
"C", | |
"D", | |
"E", | |
"F", | |
"G", | |
"H", | |
"I", | |
"J", | |
"K", | |
"L", | |
"M", | |
"N", | |
"O", | |
"P", | |
"Q", | |
"R", | |
"S", | |
"T", | |
"U", | |
"V", | |
"W", | |
"X", | |
"Y", | |
"Z", | |
"1", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
"7", | |
"8", | |
"9", | |
"0" | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment