Skip to content

PyBlocks/microbit_blocks

Repository files navigation

MicroPython / micro:bit Blocks

This repository contains block definitions for the various Python APIs for the BBC micro:bit device as implemented in MicroPython.

More information about MicroPython can be found at http://micropython.org/. The APIs are documented here: https://microbit-micropython.readthedocs.io/en/latest/.

Usage

Include blocks/microbit.js and the associated generator files via script tags, like this:

<script src="microbit_blocks/blocks/microbit.js"></script>
<script src="microbit_blocks/generators/accelerometer.js"></script>
<script src="microbit_blocks/generators/buttons.js"></script>
<script src="microbit_blocks/generators/compass.js"></script>
<script src="microbit_blocks/generators/display.js"></script>
<script src="microbit_blocks/generators/image.js"></script>
<script src="microbit_blocks/generators/microbit.js"></script>
<script src="microbit_blocks/generators/music.js"></script>
<script src="microbit_blocks/generators/neopixel.js"></script>
<script src="microbit_blocks/generators/pins.js"></script>
<script src="microbit_blocks/generators/radio.js"></script>
<script src="microbit_blocks/generators/speech.js"></script>
<script src="microbit_blocks/generators/python.js"></script>

In addition, include a language file for your locale, like this:

<script src="microbit_blocks/messages/en/messages.js"></script>

Finally, make sure you include the entries demonstrated in the toolbox.xml file in your own toolbox fragment in your markup.

Block definitions

All the blocks were generated using the online block factory tool. Links to the initial work for each module are listed below. Subsequently we've made minor adjustments to the code generated by the block factory.

The JSON based definition for each block is used by the build.py script to generate the microbit.js code mentioned above. It also takes optional arguments that should be two letter ISO-639-1 language codes. The result will be a new messages.js file containing the original English phrases used in the UI placed under a messages/<CODE>/ directory (where <CODE> is the two letter language code). This should only ever be done once since the build.py command will overwrite any existing files. Once translation is complete please check the file in under source control as a pull request.

Block Code Generation

The only "hand written" code for these blocks is contained within the generators directory. Each module has an associated file containing functions that define how each block should emit valid Python code representing an interaction with the API.

Each function has an associated unit test to ensure it's returning the expected valid Python code. To run the tests simply point your browser to the tests.html file in the root of this repository. The tests themselves are found in the tests/spec/python-spec.js file. We use the Jasmine test framework (https://jasmine.github.io/).

We love contributions and bug fixes. Please read the CONTRIBUTING.rst file to find out more..! We're a friendly project and welcome contributions from anyone. We also love to help beginner programmers - if you have a question please don't hesitate to ask!

:-)

About

Blocks for the MicroPython API on the BBC micro:bit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published