# help me with my micro:bit codes

**URL:** <https://forum.makecode.com/t/help-me-with-my-micro-bit-codes/31116>\
**Category:** micro:bit\
**Created:** [October 10, 2024, 10:23pm UTC](https://forum.makecode.com/t/help-me-with-my-micro-bit-codes/31116 "2024-10-10T22:23:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahsa12341](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mahsa12341](https://forum.makecode.com/u/Mahsa12341)\
**Post date:** [October 10, 2024, 10:23pm UTC](https://forum.makecode.com/t/help-me-with-my-micro-bit-codes/31116/1 "2024-10-10T22:23:00Z")

</div>

I need to do these:  
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.

My codes are:  
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()

Can you help me which codes should I add to finish my projekt?
