2.7 KiB
basic.forever(() => {
basic.showString("Hi!");
})
input.onButtonPressed(Button.A, () => {
led.stopAnimation();
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
input.onButtonPressed(Button.B, () => {
led.stopAnimation();
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .`);
});
About
@description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
The BBC micro:bit is a pocket-size computer with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone. The BBC micro:bit was made possible by many partners.
The micro:bit provides an easy and fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it. Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices.
Hardware: The Device
Learn about the hardware components of the micro:bit to make the most of it!
Programming: Blocks or JavaScript
You can program the micro:bit using Blocks or JavaScript, via the micro:bit APIs:
input.onButtonPressed(Button.A, () => {
basic.showString("Hi!");
})
Compile and Flash: Your Program!
When you have your code ready, you connect your micro:bit to a computer via a USB cable, so it appears as a mounted drive (named MICROBIT).
Compilation to ARM thumb machine code from Blocks or JavaScript happens in the browser. You save the ARM binary program to a file, which you then copy to the micro:bit drive, which flashes the micro:bit device with the new program.
Simulator: Test Your Code
You can run your code using the 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.
C++ Runtime
The C++ micro:bit runtime, 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 micro:bit library mirrors the functions of the C++ library. When code is compiled to ARM machine code, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.
Open Source
The code for the micro:bit is open source on GitHub. Contributors are welcome!