Interact with Sprites

On mBlock 5, the script editing area for devices is separate from that for sprites. To implement the interaction between devices and sprites, 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 implemented.

Way 1: (Live) Broadcast

In the Live mode on mBlock 5, devices and sprites that support broadcasting can communicate with each other by broadcasting and receiving messages, and therefore the interaction between devices and sprites can be implemented.

Switch the mode to "Live", and you can see all "Broadcast" blocks in the "Events" blocks.

Supported Devices

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

Connection Mode

Live

Application Scenarios

Transmitting/receiving messages (instructions) to/from each other by a device and sprite and by a sprite and another.

Application instance

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

Program Codey as follows.

Program Panda as follows.

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

Way 2: Upload Mode Broadcast

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

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

Switch the mode to "Upload" and add "Upload Mode Broadcast" separately from the device extension center and sprite extension center. Then, you can see the corresponding blocks in the script areas for the device and sprite.


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

Codey, HaloCode, mBot, mBot Ranger, Arduino Uno, Arduino Mega2560

Connection mode

Upload

Application Scenarios

A. Transmitting/receiving messages (instructions) with values to/from each other by a device and sprite.

B. Line-following, Breathing light, and other projects that require high efficiency of code operation.

Application instance

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

Program Codey as follows.

Program Panda as follows.

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 function, you can share data across devices and projects with the same mBlock 5 account.

To implement the "User cloud message" function, a device must provide the Wi-Fi function. Currently, only HaloCode supports this function.

To implement the User cloud message function for HaloCode, click Wi-Fi in the Blocks area. The corresponding blocks are displayed.

To implement the User cloud message function for a sprite, add User cloud message from Extension center. The corresponding blocks are displayed.


Connection Mode

Upload

Application Scenarios

A. Transmitting/receiving messages (instructions) with values to/from each other by a device and sprite, by a sprite and another, or by a device and another.

B. Across-region interaction. The physical distance is no longer a restriction. With the same mBlock 5 account, you can see the noise level of Shenzhen in Beijing.

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.

Program Panda as follows.

After completing the program, upload it to the device 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.

results matching ""

    No results matching ""