The project consists of two programs:
microPlane.ubp written in MicroBLocks - provides data from the attached micro:bit device.
microPlane.xml written in BeetleBlocks - models the flying plane based on accelerator values received from the MicroBlocks program.
Screenshots of both programs are presented below.
This project uses the HTTP Server feature added to the latest MicroBlocks release. Please note that this is only available on the stand-alone version of the MicroBlocks, and not the browser version.
BeetleBlocks IDE, which is a derivative of the SNAP! IDE, provides 3D modelling support based on the block programming paradigm. Both MicroBlocks IDE and BeetleBlocks IDE make use of the HTTP capabilities built-in, to establish communication between the two programs.
On the MicroBlocks side is a very simple program that steadily updates the x, y, and z accelerator values from the attached micro:bit device.
On the BeetleBlocks side is a bit more complicated program that does three things:
HTTP server of the MicroBlocks IDE is activated by first selecting show advanced blocks option in the MicroBlocks menu, followed by start HTTP server.
This initiates the server at port 6473 of the IP address of the PC where MicroBlocks is running. This location can more easily be addressed by :
HTTP server provides a simple set of services as shown below:
MicroBlocks HTTP Server
/ - this help text
/getBroadcasts - get broadcasts from board, (URL-encoded strings, one per line)
/broadcast/URL_encoded_message - broadcast message to board
/getVar/URL_encoded_var_name - get variable value
/setVar/URL_encoded_var_name/value - set variable value
(value is: true, false, an integer, or a url_encoded_string (up to 800 bytes))
(use double-quotes for string values that would otherwise be treated as a boolean or integer such as "true", "false", or "12345")
HTTP Link between the programs is established with the help of the two URL blocks in the BeetleBlocks program.
block is used to notify MicroBlocks program that BeetleBlocks program is all setup and ready to receive the accelerator data. This is done by modifying a boolean variable called tilt in the MicroBlocks program to true over the HTTP link:
This setting starts the updating of the accelerator data in the MicroBlocks program.
block is positioned in a loop on the BettleBlocks side, that constantly requests the accelerator values stored in the tiltValue variable in the MicroBlocks program:
In the MicroBlocks program, the accelerator values from the micro:bit device are placed in a list of three items, one for each of the x, y, and z values.
Triggered by the true setting of the tilt boolean variable, a simple when block keeps updating these values.
There are a few more coding details on the BeetleBlocks side that have to do with the control of the link establishment and synchronization of the two sides. But these are not that important.
Then the fun starts !
It is suggested that the BeetleBlocks inital screen display be slightly rotated to make the plane face away from the user maybe at 45 degrees, as shown in the screen shot of the BB program above. That way, the micro:bit movements are matched to the plane orientation and it is easier to coordinate the maneuvers. This orientation can be totally changed while using the program.