Hello
these are my codes:
input.onButtonPressed(Button.A, function () {
userinput = “” + userinput + “.”
save_morseCode(userinput)
})
function save_morseCode (text: string) {
basic.clearScreen()
y = 0
indexInt = 0
for (let value of text) {
if (value == “.”) {
led.plot(0, y)
led.plot(1, y)
} else {
led.plot(0, y)
led.plot(1, y)
led.plot(2, y)
led.plot(3, y)
}
y += 1
}
}
input.onButtonPressed(Button.AB, function () {
randomLetterIndex = alphabet.indexOf(randomLetter)
userInputIndex = morseAlphabet.indexOf(userinput)
if (userInputIndex == -1) {
basic.showString(“?”)
} else if (randomLetterIndex == userInputIndex) {
basic.showIcon(IconNames.Yes)
score += 1
} else {
basic.showIcon(IconNames.No)
basic.showNumber(score)
score = 0
}
userinput = “”
write_randomLetter()
})
function makeLists () {
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”
]
morseAlphabet = [
“.-”,
“-…”,
“-.-.”,
“-…”,
“.”,
“…-.”,
“–.”,
“…”,
“…”,
“.—”,
“-.-”,
“.-…”,
“–”,
“-.”,
“—”,
“.–.”,
“–.-”,
“.-.”,
“…”,
“-”,
“…-”,
“…-”,
“.–”,
“-…-”,
“-.–”,
“–…”
]
}
input.onButtonPressed(Button.B, function () {
userinput = “” + userinput + “-”
save_morseCode(userinput)
})
input.onGesture(Gesture.Shake, function () {
basic.clearScreen()
userinput = “”
})
function write_randomLetter () {
basic.showLeds( # # # # # # # # # # # # # # # # # # # # # # # # #
)
basic.pause(100)
basic.clearScreen()
basic.showString(“” + (randomLetter))
randomLetter = alphabet._pickRandom()
newRandomLetter = alphabet._pickRandom()
while (randomLetter == newRandomLetter) {
newRandomLetter = alphabet._pickRandom()
}
randomLetter = newRandomLetter
basic.showString(“” + (randomLetter))
}
let newRandomLetter = “”
let score = 0
let morseAlphabet: string =
let userInputIndex = 0
let randomLetter = “”
let alphabet: string =
let randomLetterIndex = 0
let indexInt = 0
let y = 0
let userinput = “”
makeLists()
write_randomLetter()
but I need help to do these options too:
Write one character, one signal at a time. Save the character using buttons A+B. This way, you can form a message, meaning several characters in a row. Having a system for spaces is optional. (You should also be able to shake the Micro
to clear the input.)
If nothing has been written (the screen is empty), pressing A+B should instead send the message over the radio to another Micro
.
The user should be able to send a word or a sentence in one transmission.
The receiver should be able to scroll through the Morse code (not letters) in the received message using buttons A and B, and then “reveal” the message by pressing A+B.
You must handle the situation where the user tries to write or send a combination that is not valid Morse code; this can be done either on the sender’s side or the receiver’s side (e.g., by showing a question mark).
After the message is revealed, the receiver should be able to respond (in Morse code, of course) and send a message back.
The same code should run on all Micro
, meaning no separate server/client code.
Please send me your codes if you kan help me.