Microbits have built in bluetooth transmitters which can be used to connect to computers and other micro bits. In these examples we will learn how to use these features briefly to communicate through microbits. They have 255 channels to broadcast and receive on.
Set the channel - make sure or microbits are on the same channel
Send a string
On Radio received - show the string
input.onGesture(Gesture.Shake, function () {
tool = Math.randomRange(0, 2)
if (tool == 0) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else if (tool == 1) {
basic.showIcon(IconNames.Square)
} else {
basic.showIcon(IconNames.Scissors)
}
})
input.onButtonPressed(Button.A, function () {
if (tool == 0) {
radio.sendNumber(0)
} else if (tool == 1) {
radio.sendNumber(1)
} else {
radio.sendNumber(2)
}
})
radio.onReceivedNumber(function (receivedNumber) {
if (tool == 0 && receivedNumber == 2) {
basic.showString("W")
} else if (tool == 0 && receivedNumber == 1) {
basic.showString("L")
} else if (tool == 1 && receivedNumber == 2) {
basic.showString("L")
} else if (tool == 1 && receivedNumber == 0) {
basic.showString("W")
} else if (tool == 2 && receivedNumber == 0) {
basic.showString("L")
} else if (tool == 2 && receivedNumber == 1) {
basic.showString("W")
} else {
basic.showString("D")
}
})
let tool = 0
radio.setGroup(1)
basic.forever(function () {
})