Mini Chat

Introduction

Two Calliope mini connected via radio

Use the radio to send and receive messages with other Calliope mini.

Sending a message

Use ||input:on button pressed|| to send a text message over radio with ||radio:send string||. Every Calliope mini nearby will receive this message.

input.onButtonPressed(Button.A, () => {
    radio.sendString("Yo");
});

Receiving a message

Add a ||radio:on received string|| block to run when a message is received.

radio.onReceivedString(function (receivedString) {
})

Displaying text

Add a ||basic:show string|| to display the string on the screen. Pull the ||variables:receivedString|| out of ||radio:on received string|| and put it into ||basic:show string||.

radio.onReceivedString(function (receivedString) {
    basic.showString(receivedString);
})

Testing in the simulator

Press button A on the simulator, you will notice that a second Calliope mini appears (if your screen is too small, the simulator might decide not to show it). Try pressing A again and notice that the “Yo” message gets displayed on the other Calliope mini.

input.onButtonPressed(Button.A, () => {
    radio.sendString("Yo");
});
radio.onReceivedString(function (receivedString) {
    basic.showString(receivedString);
})

Try it for real

If you two Calliope minis, download the program to each one. Press button A on one and see if the other gets a message.

Groups

Use the ||radio:set group|| block to assign a group number to your program. You will only receive messages from Calliope minis within the same group. Use this to avoid receiving messages from every Calliope mini that is transmitting.

radio.setGroup(123)
radio