More info bbc micro:bit

The TouchDevelop team is proud to be part of the BBC micro:bit project. The micro:bit is a small wearable and programmable mbed-based device that visibly features a 5×5 LED display, accelerometer, compass, buttons, I/O pins, Micro USB plug, Bluetooth Low Energy antenna, ARM Cortex-M0 processor, and battery plug.


Languages, Editors, Compilers
We extended TouchDevelop to support a progression of languages with accompanying browser-based editors. The Block Editor provides an introduction to structured programming via blocks that can be snapped together. TouchDevelop introduces a statically-typed scripting language with syntax-directed editor.


Browser-based compilers from the Block Editor to TouchDevelop and from TouchDevelop to C++ automate the transition from a visual language to a text-based language, and then to the language (C++) of the mbed-based micro:bit. The first compiler allows a student to convert a Block Editor script into a TouchDevelop script with a single press of a button.


Coding with TouchDevelop
To go from the world of browser-based scripting languages to that of the micro:bit’s ARM Cortex-M0 Processor , we defined a subset of the TouchDevelop language for programming the micro:bit. Here’s an example of a TouchDevelop script that counts up as the user presses the A button:

The language subset contains: while and for loops; if-then-else conditional statement; functions; local and global variables; integer, boolean, string and image types; operations over values of the above types; user-defined event handlers and libraries.


Compile and Flash
When a student has her TouchDevelop script ready, she can connect her micro:bit to a computer via a USB cable, so it appears as a mounted drive.

Compilation from TouchDevelop to the micro:bit proceeds into two steps. The first step (Compiler 1) compiles the TouchDevelop script to a C++ program , in the web browser.

This C++ program then is sent to ARM’s mbed compiler service where the second compilation step (Compiler 2) takes place, compiling the C++ program into an ARM binary program number 3, which is sent back to the web browser.

The student is prompted to save the ARM binary program to a file, which she then simply drags to the micro:bit mounted drive, which flashes the micro:bit device number 4 with the new program.



Simulator: Test Your Code
Before a student compiles her script for the micro:bit, she can run it using the TouchDevelop micro:bit simulator, all within the confines of a web browser. The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins.


To run a student’s TouchDevelop script in the web browser, TouchDevelop compiles it into JavaScript, the scripting language built into all web browsers.


C++ and TouchDevelop Libraries
The C++ micro:bit library, created at Lancaster University, provides access to the hardware functions of the micro:bit, as well as a set of helper functions (such as displaying a number/image/string on the LED screen). The TouchDevelop micro:bit library mirrors the functions of the C++ library. When a TouchDevelop script is compiled to C++, the calls to TouchDevelop micro:bit functions are replaced with calls to the corresponding C++ functions.
Above, see the mapping from the TouchDevelop “show number” function to its corresponding the C++ function.


Leave a Reply

Your email address will not be published. Required fields are marked *