On mBlock 5, device programming is separate from stage programming. To enable a device to interact with a sprite, for example, making the indicators of Halocode on through programming a sprite or enabling a sprite to tell the value measured by the ultrasonic sensor of mBot, you need to use the broadcast functions to transmit and receive messages (instructions) and values.


Supported devices, communication modes, and connection modes vary according to broadcast mode. Now, let's see how the interaction between a device and sprite is enabled.

Way 1: (Live) Broadcast


In Live mode on mBlock 5, devices and sprites that support broadcasting can communicate with each other by broadcasting and receiving broadcast messages.


Set the programming mode to Live.

You can see the broadcast blocks in the Events category.

image.png

Supported Devices

CyberPi, Halocode, Codey, mBot, mBot Ranger, Ultimate 2.0, MegaPi Pro, Neuron, Bluetooth Controller, Arduino Uno, and Arduino Mega2560

Connection Mode

Live

Application Scenarios

Application instance

When button A on Codey is pressed, Panda moves to a random position on the stage.


Program Codey as follows.

image


Program Panda as follows.

image


Press button A on Codey. Does Panda move on the stage?

Way 2: Upload Mode Broadcast

By using the Upload Mode Broadcast extension, devices and sprites that support this mode can interact with each other.


Note:

Ensure that the device is connected to mBlock 5 when using Upload Mode Broadcast. If being disconnected, the device cannot interact with sprites properly.


Set the programming to Upload and add the Upload Mode Broadcast extension separately for the device and sprite.

interaction.png

What can we do with a value?


When communicating with each other, a device or sprite can tell the other the type and numerical value of a message. For example, if Halocode transmits an upload mode broadcast message (volume) with a value (volume of the microphone) to Panda on the stage, Panda can tell the specific numerical value received in the message.

Supported devices

CyberPi, Codey, Halocode, mBot, mBot Ranger, Arduino Uno, Arduino Mega2560

Connection mode

Upload

Application Scenarios

Application instance

When you click Panda on the stage, Codey starts to glance around.


Program Codey as follows.

interact-with-sprite-7.png

Program Panda as follows.

image


After completing the program, upload it to the device, keep the device connected to mBlock 5, and click Panda on the stage. Does Codey glance around?

Way 3: User Cloud Message

By using the User Cloud Message extension, you can share data across devices and projects with the same mBlock 5 account.


Note:

To use the User cloud message extension, a device must provide the Wi-Fi connection function. Currently, only CyberPi and Halocode are equipped with the Wi-Fi module.


To use the user cloud message function for CyberPi, click the IoT category .

You can see the user cloud message blocks in the blocks area.

image.png

To use the user cloud message function for Halocode, click the Wi-Fi category .

You can see the user cloud message blocks in the blocks area.

image.png


To use the user cloud message function for a sprite, add the User cloud message extension from the extension center.

image.png

Connection Mode

Upload

Application Scenarios

Application instance

When you click the green flag under the stage, the LED indicators on Halocode start to play the rainbow animation.


Program Halocode as follows.

image


Program Panda as follows.

image


After completing the program, upload it to Halocode and click the green flag on the stage. Does Halocode play the rainbow animation?


Note:

After Halocode is connected to the Internet, you can also control it remotely by signing in with the same mBlock 5 account on another computer.