# MicroCode for micro:bit

## Overview

[MicroCode](https://aka.ms/m9) is a icon-based (text-free), keyboard friendly editor for the micro:bit V2. It is suitable for younger learners and users with variable accessibility needs.

![Smiley Buttons MicroCode program](https://microsoft.github.io/microcode/docs/images/generated/sample_chuck_a_duck.png)


-   Kid-friendly, icon-based, structured [web-based](https://aka.ms/m9) code editor
-   Live, the code is downloaded to the micro:bit on every edit
-   Cursor based navigation with keyboard (switch access compatible), mouse, touch, screen reader support
-   Accessories (LEDs, servos, ...) supported via [Jacdac](https://aka.ms/jacdac)

MicroCode is open source at https://github.com/microsoft/microcode.

Warning: 

## Parts

Please be sure the micro:bit is a V2 (Version 2). This project doesn't work with the original / V1 board.

Featured
### BBC micro:bit v2

[BBC micro:bit v2](https://www.adafruit.com/product/4781)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4781)
[Related Guides to the Product](https://learn.adafruit.com/products/4781/guides)
![Angled shot of a BBC micro:bit v2. ](https://cdn-shop.adafruit.com/640x480/4781-04.jpg)

or

Featured
### micro:bit v2 Go Bundle - Batteries and USB Cable Included

[micro:bit v2 Go Bundle - Batteries and USB Cable Included](https://www.adafruit.com/product/4834)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4834)
[Related Guides to the Product](https://learn.adafruit.com/products/4834/guides)
![Top down view of micro:bit v2 Go Bundle, Batteries and USB Cable.](https://cdn-shop.adafruit.com/640x480/4834-05.jpg)

# MicroCode for micro:bit

## First Program

Here is a screenshot of one the first examples in MicroCode: **smiley buttons**.

![Smiley Buttons MicroCode program](https://microsoft.github.io/microcode/docs/images/generated/sample_smiley_buttons.png)

The goal of this program is to show a smiley and plays a happy sound when pressing A, and a frowney animation and unhappy sound when B is pressed.

The  [MicroCode language](https://microsoft.github.io/microcode/docs/language), is defined in terms of **pages**, where a page has a list of **rules**, and each rule consists of a **When** section and a **Do** section, each with a list of programming **tiles**. For this example, we have 4 rules.

The first rule tells MicroCode to show an image when 'A' is pressed on the micro:bit.

You will find more [samples](https://microsoft.github.io/microcode/docs/samples) in the MicroCode documentation.

![when button A pressed, show image smiley](https://microsoft.github.io/microcode/docs/images/generated/sample_smiley_buttons_page_1_rule_1.png)

-   **when** ![press](https://microsoft.github.io/microcode/docs/images/generated/icon_S2.png) press ![button A](https://microsoft.github.io/microcode/docs/images/generated/icon_F3.png) button A, **do** ![screen](https://microsoft.github.io/microcode/docs/images/generated/icon_A5.png) show image smiley.

The next rule tells MicroCode to play a sound when 'A' is pressed as well. All rules run at the same time.

![when button A pressed, play happy sound](https://microsoft.github.io/microcode/docs/images/generated/sample_smiley_buttons_page_1_rule_2.png)

-   **when** ![press](https://microsoft.github.io/microcode/docs/images/generated/icon_S2.png) press ![button A](https://microsoft.github.io/microcode/docs/images/generated/icon_F3.png) button A, **do** ![speaker](https://microsoft.github.io/microcode/docs/images/generated/icon_A2.png) play sound emoji ![emoji happy](https://microsoft.github.io/microcode/docs/images/generated/icon_M19happy.png) happy.

The next two rules are similar but for button 'B'. 

# MicroCode for micro:bit

## Web Editor

https://www.youtube.com/watch?v=mbF-HU9IZ-A

The MicroCode web editor is at [aka.ms/m9](https://aka.ms/m9). It requires a browser with WebUSB support.

-   `Left`, `Right`, `Up`, `Down` moves the cursor
-   the `Left` and `Right` keys will wrap around in the editor on the **same** page
-   the `Up` key on top of the screen will act as `back`. It will go back the pages until page 1 is in focus, then pressing up will go back to the start screen.
-   the `Down` key will wrap around the pages
-   `Enter` or `Space` for `A` button
-   `Backspace` for `B` button
-   `]` or `Page Up` to go to the next page, `[` or `Page Down` to go to the previous page
-   Copy the URL to share your program.

## Automatic download to micro:bit V2

When the editor does not detect a micro:bit connected to the computer, it will automatically prompt you with instructions
on how to connect (requires WebUSB).

Once your micro:bit V2 is paired, the web editor will be able to download your MicroCode program to your micro:bit. This happens on every edit, so your program is always up-to-date (and running)!

If your micro:bit disconnects, you will see a micro:bit icon show up on the upper left corner of the editor.
Click on that button to reconnect again.

## Accessibility

MicroCode has a lot of accessibility goodness:
- fully keyboard enabled, and switch panel friendly. Only 3 keys are need to use MicroCode.
- tooltip read aloud and screen reader support
- game console support (XBox, ...)

# MicroCode for micro:bit

## Accessories

Additional sensors and actuators can be add as [Jacdac](https://aka.ms/jacdac) modules. MicroCode automatically detect additional hardware and will show the additional tiles if supported.

The [railroad crossing sample](https://microsoft.github.io/microcode/docs/samples/railroad-crossing) shows a program using a servo and a LED ring Jacdac module.

![Railroad crossing MicroCode program](https://microsoft.github.io/microcode/docs/images/generated/sample_railroad_crossing.png)

The ![servo set angle tile](https://microsoft.github.io/microcode/docs/images/generated/icon_A21_.png) `servo` uses a [servo motor](https://microsoft.github.io/jacdac-docs/services/servo/) move to move an physical arm. The ![servo set angle tile](https://microsoft.github.io/microcode/docs/images/generated/icon_A21_.png) `servo` arm orientation is mapped to the wall clock hours: `0` (or `12`) is on rotated 90 degree from the resting position to the left, `6` is rotated 90 degree right from the rest position.
There is also a secret animation mode when you press the micro:bit logo button.

![when press button A, do move servo to 1 o'clock](https://microsoft.github.io/microcode/docs/images/generated/sample_railroad_crossing_page_1_rule_1.png)

-   **when** ![press](https://microsoft.github.io/microcode/docs/images/generated/icon_S2.png) press ![button A](https://microsoft.github.io/microcode/docs/images/generated/icon_F3.png) button A, **do** ![servo set angle](https://microsoft.github.io/microcode/docs/images/generated/icon_A21_.png) servo set arm to 1 o'clock.

The ![LED](https://microsoft.github.io/microcode/docs/images/generated/icon_A8.png) `LED` uses a [programmable LED ring](https://microsoft.github.io/jacdac-docs/services/led/) module to display blue and red colors.

![when press button A, turn LEDs to red](https://microsoft.github.io/microcode/docs/images/generated/sample_railroad_crossing_page_1_rule_2.png)

-   **when** ![press](https://microsoft.github.io/microcode/docs/images/generated/icon_S2.png) press ![button A](https://microsoft.github.io/microcode/docs/images/generated/icon_F3.png) button A, **do** ![LED](https://microsoft.github.io/microcode/docs/images/generated/icon_A8.png) LED set all color to ![red](https://microsoft.github.io/microcode/docs/images/generated/icon_A20_1.png) red, black and repeat.



## Guide Products

### BBC micro:bit v2

[BBC micro:bit v2](https://www.adafruit.com/product/4781)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4781)
[Related Guides to the Product](https://learn.adafruit.com/products/4781/guides)
### micro:bit v2 Go Bundle - Batteries and USB Cable Included

[micro:bit v2 Go Bundle - Batteries and USB Cable Included](https://www.adafruit.com/product/4834)
Meet the new **BBC micro:bit v2** - Upgraded with a powerful new processor that has tons more capability and also adds more sensing with a new speaker and microphone!

The latest micro:bit will fit right into your existing lessons and materials; all the...

In Stock
[Buy Now](https://www.adafruit.com/product/4834)
[Related Guides to the Product](https://learn.adafruit.com/products/4834/guides)

## Related Guides

- [Wirelessly Code your Bluetooth Device with CircuitPython](https://learn.adafruit.com/wirelessly-code-your-bluetooth-device-with-circuitpython.md)
- [Using NeoPixels with Netduino Plus 2](https://learn.adafruit.com/using-neopixels-with-netduino.md)
- [DIY Google's "Physical Web" UriBeacons with the Bluefruit LE Friend](https://learn.adafruit.com/google-physical-web-uribeacon-with-the-bluefruit-le-friend.md)
- [The PICsellator](https://learn.adafruit.com/the-picsellator.md)
- [Quickstart IoT - Raspberry Pi Pico RP2040 with WiFi ](https://learn.adafruit.com/quickstart-rp2040-pico-with-wifi-and-circuitpython.md)
- [AI 3D Printed Figure](https://learn.adafruit.com/ai-figure.md)
- [A Z80 CP/M emulator for the SAMD51](https://learn.adafruit.com/z80-cpm-emulator-for-the-samd51-grand-central.md)
- [The Pixif](https://learn.adafruit.com/the-pixif.md)
- [HalloWing Googly Eye](https://learn.adafruit.com/hallowing-googly-eye.md)
- [Native MP3 decoding on Arduino](https://learn.adafruit.com/native-mp3-decoding-on-arduino.md)
- [UNTZtrument: a Trellis MIDI Instrument](https://learn.adafruit.com/untztrument-trellis-midi-instrument.md)
- [Best Beginner Boards for Teachers](https://learn.adafruit.com/best-beginner-boards-for-teachers.md)
- [micro:bit Lesson 4. Sensing Light](https://learn.adafruit.com/micro-bit-lesson-4-sensing-light-and-temperature.md)
- [Qu'est-ce que MakeCode?](https://learn.adafruit.com/makecode-fr.md)
- [sino:bit MicroPython](https://learn.adafruit.com/sino-bit-micropython.md)
