Compare commits

..

50 Commits

Author SHA1 Message Date
43c7692a8f 0.2.160 2016-06-14 06:40:57 -07:00
7f05de734c Bump pxt-core to 0.2.171 2016-06-14 06:40:55 -07:00
fe39eec686 fixing color, help of io pin service 2016-06-14 06:40:44 -07:00
655fa0fde8 updated annotations 2016-06-14 06:33:18 -07:00
2841df6950 added 'microbit-bluetooth' package 2016-06-14 06:30:07 -07:00
713dfec949 pass over LED screen 2016-06-13 21:43:01 -04:00
23c4087830 Rewrote in simple language. 2016-06-13 15:47:08 -07:00
de293be4fc Rewrote (2nd pass). Changed to . 2016-06-13 14:15:39 -07:00
4e54649ce7 Rewrote in simpler language 2016-06-13 13:39:05 -07:00
caeef2f1e1 Rewrote in simple language 2016-06-13 12:57:42 -07:00
f3d7693a26 typos 2016-06-13 14:53:08 -04:00
2ceece6cdf typos 2016-06-13 14:49:07 -04:00
c2913aea82 fix typos 2016-06-13 14:41:08 -04:00
bf90e01e7e 0.2.159 2016-06-12 06:26:57 -07:00
bbee53607b updated square image 2016-06-12 06:26:45 -07:00
e94e2e7dc4 remove references to language primitives 2016-06-12 08:16:04 -04:00
02a0839a4e typos 2016-06-11 22:37:09 -04:00
67ea6c01f2 remove linksto lessons from references 2016-06-11 22:28:57 -04:00
5b5cac878b starting to reorganize lessons 2016-06-11 22:15:36 -04:00
56301d2d6f linking in maker activities 2016-06-11 21:12:08 -04:00
f8e80e6a9d pics for music 2016-06-11 20:54:12 -04:00
d1f314d790 added compass 2016-06-11 19:43:54 -04:00
27f39b4458 move rock paper scissors to correct position 2016-06-11 18:08:05 -04:00
0c40f79dec three projects down 2016-06-11 17:12:12 -04:00
346ec3d1a6 finish second lesson 2016-06-11 14:40:09 -04:00
5a2896808e fix up pics 2016-06-10 23:39:30 -04:00
4a34edeab0 get it in the menu 2016-06-10 23:15:12 -04:00
5c2833978b name change 2016-06-10 23:10:32 -04:00
edfc2274a2 change name 2016-06-10 23:10:00 -04:00
899c9fd8d6 finish first lesson 2016-06-10 23:09:18 -04:00
13f63c2f46 Rewrote in simple language. Purged legacy example. 2016-06-10 16:13:37 -07:00
8841c47638 Rewrote in simple language. Fixed some typos. 2016-06-10 14:44:49 -07:00
c6f5a8dcc6 updated help links. fix for #90 2016-06-09 21:41:41 -07:00
786c5f9733 0.2.158 2016-06-09 21:14:54 -07:00
0cdedd02b4 updated rendering of buttons 2016-06-09 21:14:33 -07:00
aba028b1e8 Rewrote in simple language. Updated code example. 2016-06-09 18:25:59 -07:00
3049c88d5b Simulator warnings, etc. 2016-06-09 15:30:47 -07:00
8239329c2e Rewrote with simple language 2016-06-09 15:09:48 -07:00
c9d4807f25 0.2.157 2016-06-09 14:08:27 -07:00
5f4ff08c09 Bump pxt-core to 0.2.170 2016-06-09 14:08:25 -07:00
b99be68ea5 display bolts on simulator button 2016-06-09 14:08:15 -07:00
c639cc3f83 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-06-09 13:05:21 -07:00
cd56181703 Rewrote in simple language. API might not be functional. 2016-06-09 12:34:56 -07:00
5b1a807443 updated windows 10 app manifest 2016-06-09 11:49:40 -07:00
e604b27c4f various docs updates 2016-06-09 11:10:01 -07:00
4727b105c4 Rewrote in simple language. May be an obsolete API. 2016-06-08 18:14:00 -07:00
4063b5aac8 Rewrote in simple language. Deleted redundant material. 2016-06-08 16:59:20 -07:00
ee8505b4f1 0.2.156 2016-06-08 14:52:16 -07:00
ab4e2c458a Bump pxt-core to 0.2.168 2016-06-08 14:52:15 -07:00
126c236b14 New topic. Double-checked example. 2016-06-08 11:21:58 -07:00
108 changed files with 825 additions and 521 deletions

View File

@ -31,15 +31,15 @@ Just like Arduino, the micro:bit can be connected to and interact with sensors,
## Blocks or JavaScript
The student can program the BBC micro:bit using [visual blocks](http://www.github.com/Google/blockly) or JavaScript.
The student can program the BBC micro:bit using Blocks or JavaScript.
```blocks
basic.showString("BBC micro:bit!");
basic.showString("Hi!");
```
## Compile and Flash
When a user has her code ready, she can connect her BBC micro:bit to a computer via a USB cable, so it appears as a mounted drive.
When a user has her code ready, she can connect her BBC micro:bit to a computer via a USB cable, so it appears as a mounted drive (named MICROBIT).
Compilation to the ARM thumb machine code happens in the browser.
@ -47,6 +47,7 @@ The student is prompted to save the ARM binary program to a file, which she then
which flashes the micro:bit device with the new program.
## Simulator: Test Your Code
Before a student compiles her code for the micro:bit, she can run it 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.
@ -54,5 +55,10 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
The [C++ BBC micro:bit runtime](http://lancaster-university.github.io/microbit-docs/), created at [Lancaster University](http://www.lancaster.ac.uk/), 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 JavaScript 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 editor for the BBC micro:bit is [open source](/open-source) on GitHub. Contributors are welcome!

View File

@ -15,12 +15,14 @@ It flashes yellow when the system wants to tell the user that something has happ
### Buttons
Buttons A and B are a form of input. When you press a button, it completes an electrical circuit.
The micro:bit can detect either of its two buttons being pressed and un-pressed and be programmed
to act on that or send the information to another device.
The micro:bit can detect either of its two buttons being pressed/released and be programmed
to act on these events.
Button R on the back of the micro:bit is a system button. It has different uses.
When you have downloaded and run your code onto your micro:bit, press Button R to restart and run your program from the beginning.
### USB connection
When you plug in your micro:bit, it should appear as MICROBIT.
If you accidentally hold down the reset button as youre plugging in your micro:bit,
the micro:bit will appear as a MAINTENANCE drive instead of MICROBIT. This is known as maintenance mode.**
@ -43,7 +45,7 @@ This data can be used by the micro:bit in a program or be sent to another device
### Accelerometer
There is a an accelerometer on your micro:bit which detects changes in the micro:bits speed.
There is an accelerometer on your micro:bit which detects changes in the micro:bits speed.
It converts analogue information into digital form that can be used in micro:bit programs.
Output is in milli-g. The device will also detect a small number of standard actions e.g. shake, tilt and free-fall.
@ -75,7 +77,7 @@ The BBC micro:bit can send an receive data via [serial communication](/device/se
### Bluetooth Low Energy (BLE) Antenna
You will see the label BLE ANNTENA on the back of your micro:bit. It is for a messaging service,
You will see the label BLE ANTENNA on the back of your micro:bit. It is for a messaging service,
so that devices can talk to each other. The micro:bit is a peripheral
device which can talk to a central device like a smart phone or tablet that has Bluetooth Low Energy (BLE).
The micro:bit can send signals and receive signals from a central device so another BLE device can

View File

@ -1,7 +1,5 @@
# micro:bit - the device
The micro:bit device
The micro:bit is a very capable device with many components:
* [the USB connector](/device/usb)

View File

@ -11,12 +11,6 @@ This example displays a random number every time the crocodile clip holds `GND`
### Connecting Crocodile Clips
### Lessons
[love meter](/lessons/love-meter)
### See also
[micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -1,7 +1,5 @@
# The micro:bit - a reactive system
The micro:bit is a reactive system.
### Computing systems
What sort of a *computing system* is the micro:bit?

View File

@ -3,7 +3,13 @@
The micro:bit LED screen
```sim
basic.showString(" ");
basic.showLeds(`
# . # . #
. # . # .
# . # . #
. # . # .
# . # . #
`);
```
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
@ -14,15 +20,15 @@ You use ``x , y`` coordinates to specify a particular LED in the grid; where ``x
Here are the x, y coordinates for the LEDs in the 5X5 grid:
`0, 0` `1, 0` `2, 0` `3, 0` `4, 0`
`(0,0)` `(1,0)` `(2,0)` `(3,0)` `(4,0)`
`0, 1` `1, 1` `2, 1` `3, 1` `4, 1`
`(0,1)` `(1,1)` `(2,1)` `(3,1)` `(4,1)`
`0, 2` `1, 2` `2, 2` `3, 2` `4, 2`
`(0,2)` `(1,2)` `(2,2)` `(3,2)` `(4,2)`
`0, 3` `1, 3` `2, 3` `3, 3` `4, 3`
`(0,3)` `(1,3)` `(2,3)` `(3,3)` `(4,3)`
`0, 4` `1, 4` `2, 4` `3, 4` `4, 4`
`(0,4)` `(1,4)` `(2,4)` `(3,4)` `(4,4)`
The x, y coordinates for the LED in the centre of the grid are `2, 2`. Starting from `0, 0` count over 2 columns and then down 2 rows.
@ -35,7 +41,8 @@ Since the row and column numbers start at 0, an easy way to figure out the x, y
Use [plot](/reference/led/plot) and [unplot](/reference/led/unplot) to turn a LED on or off
```blocks
led.plot(0,0)
led.plot(0,0);
basic.pause(1000);
led.unplot(0,0)
```

View File

@ -11,16 +11,35 @@ input.onButtonPressed(Button.A, () => {
})
```
Data is also automatically streamed to serial by the ** bar graph** block
and picked up by the editor. This data can be streamed to the cloud as well.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0);
});
```
## How to read the micro:bit's serial output from your computer
Unfortunately, using the serial library requires quite a bit of a setup.
### BBC micro:bit Chrome Extension
If you are using the Google Chrome browser, you can use our extension to get serial data streaming in the editor.
* Install the [Extension for BBC micro:bit](https://chrome.google.com/webstore/detail/extension-for-bbc-microbi/cihhkhnngbjlhahcfmhekmbnnjcjdbge?hl=en-US) on the Chrome Web Store.
* Restart Chrome and open the web editor.
### Windows
You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it:
* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver
* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
#### Windows > Tera Term
* Install the terminal emulator [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm.
@ -32,7 +51,7 @@ You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to eras
Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time.
### Alternative Windows setup with Putty
#### Windows > Putty
If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions.

View File

@ -27,7 +27,7 @@ input.onButtonPressed(Button.B, () => {
* **[getting started](/getting-started)**
* Browse the [API reference](/reference)
* Learn more about the [device](/device)
* Get started with [lessons](/lessons)
* Get started with [projects](/projects)
* Frequently Asked Question [faq](/faq)
* Follow up with the [release notes](/release-notes)

View File

@ -51,7 +51,6 @@
### ~column
## Maker
* [The Watch](/lessons/the-watch), design and create The Watch
* [Hack your Headphones](/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones
* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits
* [Telegraph](/lessons/telegraph), play the telegraph game between two BBC micro:bits

View File

@ -38,7 +38,6 @@ Overview of Blocks lessons for the BBC micro:bit.
## Engineering
* [The Watch](/lessons/the-watch), design and create The Watch
* [Truth or dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/lessons/spinner), spin the arrow with multiple if statements
* [Dice roll](/lessons/dice-roll), spin with more if statements

View File

@ -1,23 +0,0 @@
# the watch lesson
display beautiful images on the BBC micro:bit.
![](/static/mb/lessons/the-watch-0.png)
## Topic
The Watch
## Quick Links
* [activity](/lessons/the-watch/activity)
## Prior learning/place of lesson in scheme of work
Learn how to design the BBC micro:bit watch with household supplies.
## Objectives
* learn how to design and make the watch with the BBC micro:bit

View File

@ -4,6 +4,6 @@ The editor is open source on GitHub under the MIT license. Contributions are wel
### Repos
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit, also includes the documentation.
* [microbit/pxt](https://github.com/Microsoft/pxt), programming experience toolkit (PXT)
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit
* [microsoft/pxt-microbit-core](https://github.com/Microsoft/pxt-microbit-core), Yotta module used to build the BBC micro:bit runtime

View File

@ -1,15 +1,46 @@
# Projects
![](/static/mb/projects/all10.png)
### @short Projects
## [Flashing Heart](/projects/flashing-heart)
### ~column
![](/static/mb/projects/a1-display.png)
## Beginner
## [Smiley Buttons](/projects/smiley-buttons)
* [Rock Paper Scissors](/projects/rock-paper-scissors)
![](/static/mb/projects/a2-buttons.png)
## [Love Meter](/projects/love-meter)
![](/static/mb/projects/a3-pins.png)
## [Rock Paper Scissors](/projects/rock-paper-scissors)
![](/static/mb/projects/a4-motion.png)
## [Compass](/projects/compass)
![](/static/mb/projects/a5-compass.png)
## [Hack your headphones](/lessons/hack-your-headphones/activity)
![](/static/mb/projects/a6-music.png)
## [Banana keyboard](/lessons/banana-keyboard/activity)
![](/static/mb/projects/a7-conductive.png)
## [Telegraph](/lessons/telegraph/activity)
![](/static/mb/projects/a8-network.png)
## Radio
![](/static/mb/projects/a9-radio.png)
## [Watch](/projects/the-watch)
![](/static/mb/projects/a10-watch.png)
### ~
### ~column

View File

@ -1,34 +0,0 @@
## Getting started
• Go to https://m.pxt.io/
• To create a new project, click new Project
Tap or click Blocks.
## Step 1
Use [show leds](/reference/basic/showLeds) and make your code look like this:
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
```
Once you are done coding, don't forget to run your code with the Play button.
## Step 2
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clearScreen) to turn off the LEDs.
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
```

112
docs/projects/compass.md Normal file
View File

@ -0,0 +1,112 @@
# compass activity
![](/static/mb/projects/a5-compass.png)
Display the direction that the micro:bit is facing using the compass
### ~avatar avatar
Welcome! This guided tutorial will show you how to program a script that displays the direction the micro:bit is pointing. Let's get started!
### ~
## Step 1
Create a loop that will continuously update the reading of the compass.
```blocks
basic.forever(() => {
})
```
## Step 2
Store the reading of the micro:bit in a variable called `degrees`.
```blocks
basic.forever(() => {
let degrees = input.compassHeading()
})
```
## Step 3
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the micro:bit.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
});
```
## Step 4
If `degrees` is less than 135, the micro:bit is mostly pointing East. Display `E` on the micro:bit.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
});
```
## Step 5
If `degrees` is less than 225, the micro:bit is mostly pointing South. Display `S` on the micro:bit.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
});
```
## Step 6
If none of these conditions returned true, then the micro:bit must be pointing West. Display `W` on the micro:bit.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
else {
basic.showString("W");
}
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/compass/challenges)!
### ~

View File

@ -0,0 +1,94 @@
![](/static/mb/projects/a1-display.png)
Use the LEDs to display a flashing heart.
## Step 1
Use [show leds](/reference/basic/showLeds) and make your code look like this:
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
```
## Step 2
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clearScreen) to turn off the LEDs.
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
```
## Step 3
Put a [forever loop](/reference/basic/forever) around it.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
})
```
## Step 4
Add a [pause](/reference/basic/pause) to wait after clearing the screen.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
})
```
## Step 5
Add a second image of a broken heart.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
basic.showLeds(`
. # . # .
# . # # #
# . . . #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
})
```

View File

@ -0,0 +1,48 @@
![](/static/mb/projects/a3-pins.png)
Use pins P0, P1 and P2 to change the display by creating a circuit with your body.
## Step 1
Use [on pin pressed](/reference/input/on-pin-pressed) to show a random number
when pin P0 is pressed (hold the GND pin with other hand):
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.random(11));
});
```
## Step 2
Show a string when pin P1 is pressed:
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.random(11));
});
input.onPinPressed(TouchPin.P1, () => {
basic.showString("LOVE?");
});
```
## Step 3
Show a heart when pin P2 is pressed:
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.random(11));
});
input.onPinPressed(TouchPin.P1, () => {
basic.showString("LOVE?");
});
input.onPinPressed(TouchPin.P2, () => {
basic.showLeds(`
. # # # .
# # # # #
# # # # #
. # # # .
. . # . .
`);
});
```

View File

@ -1,5 +1,7 @@
# rock paper scissors
![](/static/mb/projects/a4-motion.png)
### ~avatar avatar
```sim

View File

@ -0,0 +1,67 @@
![](/static/mb/projects/a2-buttons.png)
Use buttons to show a smiley or frowny face.
## Step 1
Use [show leds](/reference/basic/showLeds) to make a smiley face:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
```
## Step 2
Add an input block for when [button A is pressed](/reference/input/button-is-pressed), and put a
frowny face inside it:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
```
## Step 3
Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
```

View File

@ -1,6 +1,4 @@
# The watch activity
Control images with variables.
![](/static/mb/projects/a10-watch.png)
# micro:bit watch
@ -152,7 +150,7 @@ Your watch is ready!
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/rock-paper-scissors/activity)!
Excellent, you're ready to continue with the [challenges](/projects/rock-paper-scissors)!
### ~

View File

@ -1,10 +1,6 @@
# Reference
```namespaces
for (let i = 0;i<5;++i) {}
if (true){}
let x = 0;
Math.random(5);
basic.showNumber(0);
input.onButtonPressed(Button.A, () => {
@ -21,8 +17,15 @@ images.createImage(`
. . . . .
`);
pins.digitalReadPin(DigitalPin.P0);
serial.writeValue(x, 0);
serial.writeNumber(0);
control.inBackground(() => {
});
```
<!-- No language reference for now, until
for (let i = 0;i<5;++i) {}
if (true){}
let x = 0;
Math.random(5);
-->

View File

@ -21,10 +21,6 @@ basic.showLeds(`
basic.clearScreen()
```
### Lessons
[blink](/lessons/blink), [flashing heart](/lessons/flashing-heart), [screen wipe](/lessons/screen-wipe)
### See also
[set brightness](/reference/led/set-brightness), [unplot](/reference/led/unplot), [plot](/reference/led/plot), [Image](/reference/images/image), [clear](/reference/basic/clear-screen)

View File

@ -63,10 +63,6 @@ input.onButtonPressed(Button.A, () => {
})
```
### Lessons
[blink](/lessons/blink), [snowflake-fall](/lessons/snowflake-fall), [flashing-heart](/lessons/flashing-heart)
### See also
[while](/reference/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)

View File

@ -24,10 +24,6 @@ for (let i = 0; i < 5; i++) {
}
```
### Lessons
[blink](/lessons/blink), [lucky 7](/lessons/lucky-7), [smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart)
### See also
[while](/reference/loops/while), [running time](/reference/input/running-time), [for](/reference/loops/for)

View File

@ -62,8 +62,3 @@ basic.showAnimation(`
Use [forever](/reference/basic/forever) to show an animation over and over.
### ~
### Lessons
[smiley](/lessons/smiley), [snowflake fall](/lessons/snowflake-fall), [rotation animation](/lessons/rotation-animation)

View File

@ -1,6 +1,6 @@
# Show LEDs
Display an image on the BBC micro:bit's [LED screen](/device/screen).
Shows a picture on the [LED screen](/device/screen).
```sig
basic.showLeds(`
@ -15,13 +15,13 @@ basic.showLeds(`
### Parameters
* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off.
* `ms` is an optional [Number](/reference/types/number) that shows how many milliseconds to wait after showing a picture.
If you are programming with blocks, `ms` starts out as 400 milliseconds.
* `leds` is a [string](/reference/types/string) that means which LEDs are on and off.
* `interval` is an optional [number](/reference/types/number) that means how many milliseconds to wait after showing a picture.
If you are programming with blocks, `interval` starts out as 400 milliseconds.
### Example
Open the `basic` card in the Block Editor and select the `show leds` blocks.
This program shows a picture with the ``show leds`` function.
```blocks
basic.showLeds(`
@ -34,11 +34,12 @@ basic.showLeds(`
)
```
If you are programming in JavaScript, `#` means an LED that is turned on and `.` means an LED that is turned off.
### ~hint
### Lessons
If you are programming in JavaScript, `#` means an LED that is turned
on and `.` means an LED that is turned off.
[smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart), [magic logo](/lessons/magic-logo)
### ~
### See also

View File

@ -42,10 +42,6 @@ for (let i = 0; i < 6; i++) {
* Use [show string](/reference/basic/show-string) to show a [String](/reference/types/string) with letters on the screen.
* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another.
### Lessons
* [lucky 7](/lessons/lucky-7)
### See also
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/reference/math)

View File

@ -31,10 +31,6 @@ basic.showString(s)
* Use [show number](/reference/basic/show-number) to show a number on the [LED screen](/device/screen).
* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another.
### Lessons
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter)
### See also
[String](/reference/types/string), [show number](/reference/basic/show-number), [show animation](/reference/basic/show-animation)

View File

@ -24,8 +24,3 @@ export function addScore(points: number)
```
export function score() : number
```
### Lessons
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)

View File

@ -19,8 +19,3 @@ Sprite will change the y position by this number
```
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -146,8 +146,3 @@ You can also end the game by calling the `game -> game over` function:
```
game.gameOver()
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -18,7 +18,3 @@ You can end the game by calling the `game -> game over` function:
game.gameOver()
```
### Lessons
[game of chance](/lessons/game-of-chance)

View File

@ -5,8 +5,3 @@ Sprite move by a certain number of LEDs
```
export function move(_this: micro_bitSprites.LedSprite, leds: number)
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -11,8 +11,3 @@ Reports the y position of a sprite on the LED screen
```
export function y(_this: micro_bitSprites.LedSprite) : number
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -25,8 +25,3 @@ Reports the current direction of a sprite on the LED screen
```
export function direction(_this: micro_bitSprites.LedSprite) : number
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -43,7 +43,3 @@ If your game has a time limit, you can start a countdown in which case `game->cu
export function startCountdown(ms: number)
```
### Lessons
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)

View File

@ -40,8 +40,3 @@ If your game has a time limit, you can start a countdown in which case `game->cu
```
export function startCountdown(ms: number)
```
### Lessons
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -6,7 +6,3 @@ Reports true if sprite is touching specified sprite
export function isTouching(_this: micro_bitSprites.LedSprite, other: micro_bitSprites.LedSprite) : boolean
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -12,7 +12,3 @@ Rotates a sprite to the left by a certain number of degrees
export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number)
```
### Lessons
[game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -29,10 +29,6 @@ input.onGesture(Gesture.Shake, () => {
})
```
### Lessons
[rock paper scissors](/lessons/rock-paper-scissors), [digital pet](/lessons/digital-pet), [offset-image](/lessons/offset-image)
### See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/image/show-image), [scroll image](/reference/image/scroll-image)

View File

@ -46,10 +46,6 @@ You should see code similar to this:
* [show image](/reference/images/show-image): show an image on the screen
* [scroll image](/reference/images/scroll-image): scroll an image on the screen
### Lessons
* [smiley](/lessons/smiley)
### See also
[Show LEDs](/reference/basic/show-leds), [create image](/reference/images/create-image), [show image](/reference/images/show-image), [LED screen](/device/screen)

View File

@ -31,10 +31,6 @@ let img = images.createImage(`
img.plotFrame(1)
```
### Lessons
[smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart), [magic logo](/lessons/magic-logo)
### See also
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)

View File

@ -31,10 +31,6 @@ let img = images.createImage(`
img.plotImage(0)
```
### Lessons
[smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart), [magic logo](/lessons/magic-logo)
### See also
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)

View File

@ -31,10 +31,6 @@ let img = images.createImage(`
img.showFrame(1)
```
### Lessons
[smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart), [magic logo](/lessons/magic-logo)
### See also
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)

View File

@ -45,10 +45,6 @@ for (let i = 0; i < 5; i++) {
}
```
### Lessons
[rock paper scissors](/lessons/rock-paper-scissors), [digital pet](/lessons/digital-pet), [offset-image](/lessons/offset-image)
### See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)

View File

@ -2,46 +2,39 @@
Get the acceleration value (milli g-force), in one of three specified dimensions.
Find the acceleration of the micro:bit (how fast it is speeding up or slowing down).
```sig
input.acceleration(Dimension.X);
```
## ~hint
You measure acceleration with the **milli-g**, which is 1/1000 of a **g**.
A **g** is as much acceleration as you get from Earth's gravity.
## ~
### Parameters
* dimension : [String](/reference/types/string) - one of three values specifying the axis of acceleration: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down)
* which direction you are checking for acceleration, either `Dimension.X` (left and right), `Dimension.Y` (forward and backward), or `Dimension.Z` (up and down)
### Returns
* [Number](/reference/types/number) - acceleration, in milli-gravities. When the micro:bit is laying flat with the screen up, x=0, y=0 and z=-1023.
* a [number](/reference/types/number) that means the amount of acceleration. When the micro:bit is lying flat on a surface with the screen pointing up, `x` is `0`, `y` is `0`, and `z` is `-1023`.
### Example: bar chart
Use the ``plot bar chart`` to visual the acceleration on the LED screen.
This example shows the acceleration of the micro:bit with a bar graph.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration("x"), 1023)
led.plotBarGraph(input.acceleration(Dimension.X), 1023)
})
```
### Example: micro:bit leveller
The following example uses the `acceleration` and the `plot` function to help you move the micro:bit until it's level (the centre LED is *on* when the device is level). When running this code in a web browser, move your mouse to simulate the accelerometer.
```blocks
basic.forever(() => {
let ax = input.acceleration(Dimension.X)
let x = pins.map(-1023, 1023, 0, 4, ax)
let ay = input.acceleration("y")
let y = pins.map(-1023, 1023, 0, 4, ay)
basic.clearScreen()
led.plot(x, y)
})
```
### Lessons
[zoomer](/lessons/zoomer)
### See also

View File

@ -33,10 +33,6 @@ basic.forever(() => {
})
```
### Lessons
[zoomer](/lessons/zoomer)
### See also
[on button pressed](/reference/input/on-button-pressed), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -1,6 +1,10 @@
# Compass Heading
Get the compass heading of the micro:bit in degrees. Your micro:bit has a built-in **magnetometer** so it can your direction with respect to the North Magnetic Pole.
Find which direction on a compass the micro:bit is facing.
The micro:bit measures the **compass heading** from `0` to `360`
degrees with its **magnetometer** chip. Different numbers mean north,
east, south, and west.
```sig
input.compassHeading();
@ -8,15 +12,12 @@ input.compassHeading();
### Returns
* [Number](/reference/types/number) - the heading in degrees (0 to 360 degrees). If the compass is calibrating, it returns ``-1003``.
## Simulator
Calibration does not work on the simulator.
* a [number](/reference/types/number) from `0` to `360` degrees, which means the compass heading. If the compass isn't ready, it returns `-1003`.
### Example
The following code gets the compass heading and stores it in the `degrees` variable:
This program finds the compass heading and stores it in the
`degrees` variable.
```blocks
let degrees = input.compassHeading()
@ -24,13 +25,16 @@ let degrees = input.compassHeading()
### ~hint
When running code with this function in a web browser, click and drag the on-screen compass needle to change heading.
When you run a program that uses this function in a browser, click and drag
the compass needle on the screen to change the compass heading.
### ~
### Example: compass
The following example gets the `compass heading` and then displays a letter depending on the value of `degrees`: N for north, E for East, S for South, and W for West.
This program finds the compass heading and then shows a letter
that means whether the micro:bit is facing north (N), south (S),
east (E), or west (W).
```blocks
basic.forever(() => {
@ -47,17 +51,14 @@ basic.forever(() => {
### Calibration
On the first use of the compass, the **calibration** procedure will automatically start. The user must draw a circle with the device until it is fully calibrated.
Every time you start to use the compass (for example, if you have just
turned the micro:bit on), the micro:bit will start to **calibrate**
(adjust itself). It will ask you to draw a circle by tilting the
micro:bit.
An enclosure made from metal, or using in proximity of metal objects, might affect the accuracy of the reading and calibration.
During calibration, ``compass heading`` returns ``-1003``.
### Lessons
[compass](/lessons/compass)
If you are calibrating or using the compass near metal, it might
confuse the micro:bit.
### See also
[acceleration](/reference/input/acceleration)

View File

@ -43,8 +43,6 @@ basic.forever(() => {
})
```
### Lessons
### See also
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)

View File

@ -1,27 +1,35 @@
# Magnetic Force
Get the magnetic force (micro Teslas), in one of three specified dimensions.
Find the amount of magnetic force (the strength of a magnet) in the direction you say.
```sig
input.magneticForce(Dimension.X);
```
## ~hint
The micro:bit measures magnetic force with **microteslas**.
## ~
### Parameters
* dimension : [String](/reference/types/string) - one of three values specifying the axis of the force: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down); ``strength`` (the length of the vector)
* a [string](/reference/types/string) that says which direction the micro:bit should measure magnetic force in: either `x` (the left-right direction), `y` (the forward/backward direction), or `z` (the up/down direction)
### Returns
* [Number](/reference/types/number) - magnetic force, in micro-Teslas.
* a [number](/reference/types/number) of microteslas that means the strength of the magnet
### Example: metal detector
The following example uses the `magnetic force` to control the brightness of the screen. When the magnetic force increases, the center LED will appear brighter.
This program makes the center LED of the micro:bit get brighter when
the magnetic force is stronger, and dimmer when it is weaker.
```blocks
led.plot(2, 2)
basic.forever(() => {
let f = input.magneticForce(Dimension.X)
let f = input.magneticForce("x")
led.setBrightness(f / 2000)
})
```
@ -29,4 +37,3 @@ basic.forever(() => {
### See also
[compass heading](/reference/input/compass-heading)

View File

@ -41,10 +41,6 @@ Otherwise, sometimes they would show a `0`.
### ~
### Lessons
[smiley](/lessons/smiley), [answering machine](/lessons/answering-machine), [screen wipe](/lessons/screen-wipe), [rotation animation](/lessons/rotation-animation)
### See also
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/reference/math/math)

View File

@ -1,19 +1,17 @@
# On Gesture
Register an [event handler](/reference/event-handler) that will execute whenever the user executes a gesture withthe BBC micro:bit.
Start an [event handler](/reference/event-handler) (part of the
program that will run when something happens) This handler works when
you do a **gesture** (like shake, tilt, or drop the micro:bit).
```sig
input.onGesture(Gesture.Shake,() => {
})
```
## Gestures
## Example: random number
### Example: random number
The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit.
This program shows a number from `0` to `9` when you shake the micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
@ -22,24 +20,3 @@ input.onGesture(Gesture.Shake,() => {
})
```
### Example: rock, paper, scissors
The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img.showFrame(Math.random(3))
})
```
### Lessons
[bounce image](/lessons/bounce-image), [rock paper scissors](/lessons/rock-paper-scissors)

View File

@ -1,17 +1,31 @@
# On Pin Pressed
Register an [event handler](/reference/event-handler) that will execute whenever the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit; when you run a script with this function in a web browser, click pins 0 , 1, or 2 on the simulator.
Start an [event handler](/reference/event-handler) (part of the program
that will run when something happens, like when a button is pressed).
This handler works when you press pin `0`, `1`, or `2` together with `GND`.
When you are using this function in a web browser, click the pins on the screen instead of the ones
on the BBC micro:bit.
*Note* that this function works best when the BBC micro:bit is powered by AAA battery.
If you hold the `GND` pin with one hand and touch pin `0`, `1`, or `2` with the other,
a very small (safe) amount of electricity will flow through your body and back into
the micro:bit. This is called **completing a circuit**. It's like you're a big wire!
```sig
input.onPinPressed(TouchPin.P0, () => {
})
```
## ~hint
This function works best when the BBC micro:bit is using batteries for power,
instead of the USB cable.
## ~
### Example: pin pressed counter
This example counts how many times the P0 pin is pressed. Each time the pin is pressed, the global count variable is increased by 1 and displayed on the screen.
This program counts how many times you press the `P0` pin.
Every time you press the pin, the program shows the number of times on the screen.
```blocks
let count = 0
@ -22,10 +36,6 @@ input.onPinPressed(TouchPin.P0, () => {
})
```
### Lessons
[love meter](/lessons/love-meter)
### See also
[BBC micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -1,24 +1,33 @@
# Pin Is Pressed
Gets the pin state (pressed or not pressed), by detecting when the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit.
Find whether the pin you say is pressed or not pressed.
*Note* that this function works best when the BBC micro:bit is powered by AAA battery.
If you hold the `GND` pin with one hand and touch pin `0`, `1`, or `2` with the other,
a very small (safe) amount of electricity will flow through your body and back into
the micro:bit. This is called **completing a circuit**. It's like you're a big wire!
```sig
input.pinIsPressed(TouchPin.P0);
```
## ~hint
This function works best when the BBC micro:bit is using batteries for power,
instead of the USB cable.
## ~
### Parameters
* name - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
* a [string](/reference/types/string) that holds the pin name (**P0**, **P1**, or **P2**)
### returns
* [Boolean](/reference/types/boolean) - `true` if pressed, `false` if not pressed
* a [boolean](/reference/types/boolean) that means whether the pin you say is pressed (`true` or `false`)
### Example
This example displays 1 if P0 is pressed, and 0 if P0 is not pressed:
This program shows `1` if `P0` is pressed, and `0` if `P0` is not pressed:
```blocks
basic.forever(() => {

View File

@ -1,45 +1,58 @@
# Rotation
Get a rotation angle in degrees inferred from the accelerometer readings.
Find how much the micro:bit is tilted in different directions.
```sig
input.rotation(Rotation.Roll);
```
## ~hint
The BBC micro:bit has a part called the **accelerometer** that can
check how the micro:bit is moving.
## ~
### Parameters
* kind: [String](/reference/types/string) - one of values specifying the kind of rotation: ``pitch`` (up/down around the ``x`` axis); ``roll`` (left/right around the ``y`` axis)
* which direction you are checking: `Rotation.Pitch` (up and down) or `Rotation.Roll` (left and right)
### Returns
* [Number](/reference/types/number) - angle, in degrees.
* a [number](/reference/types/number) that means how much the microbit is tilted in the direction you say, from `0` to `360` degrees
### Example: micro:bit leveller
### Example: micro:bit leveler
The following example uses the `rotation` and the `plot leds` function to help you move the BBC micro:bit until it's level: when it is level, a smiley shows up on the screen. When running this code in a web browser, move your mouse to simulate the rotation.
This program helps you move the BBC micro:bit until it is level. When
it is level, the micro:bit shows a smiley.
```sig
If you are running this program in a browser, you can tilt the
micro:bit with your mouse.
```blocks
let pitch = 0;
basic.forever(() => {
let pitch = input.rotation(Rotation.Pitch)
let roll = input.rotation(Rotation.Roll)
pitch = input.rotation(Rotation.Pitch);
let roll = input.rotation(Rotation.Roll);
if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) {
basic.plotLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. # . # .
. . . . .
. . . . .
# . . . #
. # # # .
`);
} else {
basic.plotLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
basic.showLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`);
}
})
});
```
### See also

View File

@ -24,9 +24,6 @@ input.onButtonPressed(Button.B, () => {
})
```
### Lessons
[speed button](/lessons/speed-button)
### See also

View File

@ -52,8 +52,6 @@ better thermometer.
### ~
### Lessons
### See also
[compass-heading](/reference/input/compass-heading), [acceleration](/reference/input/acceleration)

View File

@ -24,10 +24,6 @@ for (let i = 0; i < 5; i++) {
}
```
### Lessons
[glowing sword](/lessons/glowing-sword)
### See also
[brightness](/reference/led/brightness), [fade out](/reference/led/fade-out), [set brightness](/reference/led/set-brightness)

View File

@ -20,10 +20,6 @@ basic.showString("A", 1000)
led.fadeOut(1000)
```
### Lessons
[glowing sword](/lessons/glowing-sword)
### See also
[brightness](/reference/led/brightness), [fade in](/reference/led/fade-in), [set brightness](/reference/led/set-brightness)

View File

@ -6,10 +6,6 @@ Turn on all the 25 LEDs on the [LED screen](/device/screen).
led.plotAll()
```
### Lessons
[night light](/lessons/night-light)
### See also
[LED screen](/device/screen), [clear screen](/reference/basic/clear-screen)

View File

@ -28,10 +28,6 @@ basic.plotLeds(`
`)
```
### Lessons
[smiley](/lessons/smiley), [flashing heart](/lessons/flashing-heart), [magic logo](/lessons/magic-logo)
### See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)

View File

@ -1,35 +1,47 @@
# Plot
Turn on a LED light on the [LED screen](/device/screen). Specify which LED using x, y coordinates. Use [unplot](/reference/led/unplot) to turn a LED off.
Turn on the LED light you say on the [LED screen](/device/screen).
```sig
led.plot(0,0);
```
## ~hint
Use [unplot](/reference/led/unplot) to turn **off** an LED.
## ~
### Parameters
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4)
* y - [Number](/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4)
* **x** is a [number](/reference/types/number) that means the horizontal spot on the LED screen (from left to right: 0, 1, 2, 3, or 4)
* **y** is a [number](/reference/types/number) that means the vertical spot on the LED screen (from top to bottom: 0, 1, 2, 3, or 4)
If a parameter is [out of bounds](/reference/out-of-bounds) (a value other than 0-4), then this function will do nothing.
If a parameter is [out of bounds](/reference/out-of-bounds) (a value
other than 0 to 4), then this function will do nothing.
### x, y coordinates?
### ~hint
The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/device/screen).
The LED screen is a solid square of LEDs with five LEDs on each side.
To learn more about how you number the LEDs with ``x`` and ``y``
coordinates, see [LED screen](/device/screen).
This code turns on the centre LED:
### ~
### Example: One LED
This program turns on the bottom right LED.
```blocks
led.plot(2, 2)
led.plot(4, 4)
```
### Get the LED on/off state
Use the [point](/reference/led/point) function to find out if a LED is on or off.
### Example: Square
### Example: a square
The following example uses a [for loop](/reference/loops/for) and the `plot` function to turn on the LED lights along the edge of the screen, making a square:
This program uses a [for loop](/reference/loops/for)
and the `plot` function
to make a square around the edges of the LED screen.
```blocks
for (let i = 0; i < 5; i++) {
@ -41,11 +53,13 @@ for (let i = 0; i < 5; i++) {
}
```
### Lessons
### ~hint
[blink](/lessons/blink), [beautiful image](/lessons/beautiful-image), [strobe light](/lessons/strobe-light)
Use the [point](/reference/led/point) function to find out if an LED is
on or off.
### ~
### See also
[unplot](/reference/led/unplot), [point](/reference/led/point), [LED screen](/device/screen)

View File

@ -1,6 +1,7 @@
# Point
Get the on/off state of a LED on the [LED screen](/device/screen). Specify the LED using x, y coordinates.
Find whether the LED you say on the
[LED screen](/device/screen) is on or off.
```sig
led.point(0,0);
@ -8,30 +9,36 @@ led.point(0,0);
### Parameters
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4)
* y - [Number](/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4)
* **x** is a [number](/reference/types/number) that means the horizontal spot on the LED screen (from left to right: 0, 1, 2, 3, or 4)
* **y** is a [number](/reference/types/number) that means the vertical spot on the LED screen (from top to bottom: 0, 1, 2, 3, or 4)
If a parameter is [out of bounds](/reference/out-of-bounds) (a value other than 0-4), then this function will return `false`.
If a parameter is [out of bounds](/reference/out-of-bounds) (a value
other than 0 to 4), this function will return `false`.
### Returns
* [Boolean](/reference/types/boolean) - `true` if the LED is *on* and `false` if the LED is *off*
* a [boolean](/reference/types/boolean). If it is `true`, that means the LED is on. If it is `false`, that means the LED is off.
### x, y coordinates?
### ~hint
The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/device/screen).
The LED screen is a solid square of LEDs with five LEDs on each side.
To learn more about how you number the LEDs with ``x`` and ``y``
coordinates, see [LED screen](/device/screen).
### Example: toggle off
### ~
If `point(1, 1)` returns `true`, then the following code turns off the LED:
### Example: Toggle off
This program turns the center LED (2, 2) off if it is already on. (If
it is already off, this program leaves it off.)
```blocks
if (led.point(1, 1)) {
led.unplot(1, 1)
if (led.point(2, 2)) {
led.unplot(2, 2)
}
```
### See also
[unplot](/reference/led/unplot), [plot](/reference/led/plot), [LED screen](/device/screen), [create image](/reference/images/create-image)
[unplot](/reference/led/unplot), [plot](/reference/led/plot), [LED screen](/device/screen)

View File

@ -21,10 +21,6 @@ basic.pause(1000)
led.setBrightness(127)
```
### Lessons
[night light](/lessons/night-light)
### See also
[brightness](/reference/led/brightness), [fade in](/reference/led/fade-in), [fade out](/reference/led/fade-out), [LED screen](/device/screen)

View File

@ -1,35 +1,36 @@
# Unplot
Turn off a LED light on the [LED screen](/device/screen). Specify which LED using x, y coordinates. Use [plot](/reference/led/plot) to turn a LED on.
Turn off the LED light you say on the [LED screen](/device/screen).
```sig
led.unplot(0,0)
```
## ~hint
Use [plot](/reference/led/plot) to turn **on** an LED.
## ~
### Parameters
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4)
* y - [Number](/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4)
* **x** is a [number](/reference/types/number) that means the horizontal spot on the LED screen (from left to right: 0, 1, 2, 3, or 4)
* **y** is a [number](/reference/types/number) that means the vertical spot on the LED screen (from top to bottom: 0, 1, 2, 3, or 4)
If a parameter is [out of bounds](/reference/out-of-bounds) (a value other than 0-4), this function will do nothing.
If a parameter is [out of bounds](/reference/out-of-bounds) (a value
other than 0 to 4), then this function will do nothing.
### x, y coordinates?
### ~hint
The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/device/screen).
The LED screen is a solid square of LEDs with five LEDs on each side.
To learn more about how you number the LEDs with ``x`` and ``y``
coordinates, see [LED screen](/device/screen).
This code turns off centre LED:
### ~
```blocks
led.unplot(2, 2)
```
### Example: Center off
### Get the LED on/off state
Use the [point](/reference/led/point) function to find out if a LED is on or off.
### Example: toggle off
This code creates and shows an image on the micro:bit screen, and then clears the centre LED using `unplot`:
This program shows a picture on the LED screen, and then turns off the center LED with `unplot`.
```blocks
basic.showLeds(`
@ -43,11 +44,14 @@ basic.pause(500)
led.unplot(2, 2)
```
### Lessons
### ~hint
Use the [point](/reference/led/point) function to find out if an LED is
on or off.
### ~
[strobe light](/lessons/strobe-light)
### See also
[plot](/reference/led/plot), [point](/reference/led/point), [LED screen](/device/screen), [create image](/reference/images/create-image)
[plot](/reference/led/plot), [point](/reference/led/point), [LED screen](/device/screen)

View File

@ -22,10 +22,6 @@ if(input.lightLevel()<100){
If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`:
### Lessons
[love meter](/lessons/love-meter), [zoomer](/lessons/zoomer)
### See also
[while loop](/reference/loops/while), [for](/reference/loops/for), [boolean](/reference/types/boolean)

View File

@ -2,7 +2,6 @@
```cards
for(let i = 0;i<5;i++) {}
for(let i = 1;i<5;i++) {}
while(true) {}
basic.forever(() => {})
```

View File

@ -14,10 +14,6 @@ basic.showNumber(i)
}
```
### Lessons
[looper](/lessons/looper)
### See also
[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -6,10 +6,6 @@ Run part of the program the number of times you say.
![](/static/mb/blocks/contents-0.png)
### Lessons
[looper](/lessons/looper)
### See also
[for](/reference/loops/for), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -26,10 +26,6 @@ while(index >= 0) {
}
```
### Lessons
[rotation animation](/lessons/rotation-animation)
### See also
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -42,10 +42,6 @@ returns a random [Number](/reference/types/number) between 0 and the parameter *
![](/static/mb/blocks/math-3.png)
### Lessons
[love meter](/lessons/love-meter)
### See also
[Block Editor documentation](/blocks/contents), [Number](/reference/types/number)

View File

@ -7,6 +7,10 @@ Run part of a program when the micro:bit receives a
* the part of the program to run when the micro:bit receives information over ``radio``.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program keeps sending numbers that says how fast the micro:bit is

View File

@ -2,10 +2,14 @@
Receives the next number sent by a micro:bit in the same ``radio`` group.
### Return value
### Returns
* the first [number](/reference/types/number) that the micro:bit received. If it did not receive any numbers, this function will return `0`.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Simple number receiver
This example receives the number broadcasted another micro:bit and shows it

View File

@ -6,10 +6,14 @@ Find the next string sent by `radio` from another micro:bit.
radio.receiveString()
```
### Return value
### Returns
* the first [string](/reference/types/string) that was sent. If no string was sent, then this function returns an empty (blank) string.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Simple receiver
Show the string sent by another micro:bit.

View File

@ -0,0 +1,36 @@
# Received Signal Strength
Find how strong the ``radio`` signal is, from `255` to `0`.
(`255` means a weak signal and `0` means a strong one.)
The micro:bit finds the signal strength by checking how strong it was
the last time it ran the
[receive number](/reference/radio/receive-number) function. That means
it needs to run **receive number** first.
### Returns
* a [number](/reference/types/number) between `255` and `0` that means
how strong the signal is.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This example shows how strong the radio signal of the
[light level sender example](/reference/input/send-number) is.
```blocks
let x = 0;
radio.setGroup(99);
basic.forever(() => {
x = radio.receiveNumber();
basic.showNumber(radio.receivedSignalStrength());
});
```
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -6,6 +6,10 @@ Broadcast a number to other micro:bits connected via ``radio``.
* num - a number to send.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Broadcasting acceleration
This example broadcasts the value of your micro:bit's ``acceleration`` in the `x` direction

View File

@ -1,7 +1,5 @@
# Send String
Sends a string to other micro:bits in the area connected by radio.
```sig
@ -12,6 +10,12 @@ radio.sendString("Hello!")
* `text` is a [String](/reference/types/string) to send by radio.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Two-way radio
If you load this program onto two or more micro:bits, you can send a code word from one of them to the others by pressing button `A`.

View File

@ -14,6 +14,10 @@ to talk to each other because they will have the same group ID.
* ``id`` is a [number](/reference/types/number) from ``0`` to ``255``.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program makes the group ID equal 128.

View File

@ -8,7 +8,7 @@ The scientific name for the strength of the ``radio`` signal is
can be measured as -30 dBm, and a strength of `7` can be
measured as +4 dBm.
## Range
### Range
If your micro:bit is sending with a strength of `7`, and you are in
an open area without many other computers around, the micro:bit signal
@ -19,6 +19,10 @@ can reach as far as 70 meters (about 230 feet).
* a [number](/reference/types/number) between ``0`` and ``7`` that
means how strong the signal is.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program makes the ``radio`` send at full strength.

View File

@ -9,21 +9,11 @@ The format for received data printed to serial is as follows
- [send value](/reference/radio/send-number) - ```{v:Value,t:MicrobitTimeAlive,s:Unused,n:"Name"}```
- [send string](/reference/radio/send-string) - ```{}``` (currently unavailable)
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
### Simulator
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.writeValueToSerial()
```
### Parameters
* None
This function only works on the micro:bit, not in browsers.
### Examples

View File

@ -98,10 +98,6 @@ if(x < 5) {
See the documentation on [Numbers](/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/reference/types/string-functions) using the `equals` function.
### Lessons
[rotation animation](/lessons/rotation-animation), [love meter](/lessons/love-meter), [zoomer](/lessons/zoomer)
### See also
[if](/reference/logic/if), [while](/reference/loops/while), [number](/reference/types/number)

View File

@ -51,10 +51,6 @@ The [math library](/reference/math) includes math related functions. In the [Blo
![](/static/mb/blocks/number-3.png)
### Lessons
[game counter](/lessons/game-counter), [love meter](/lessons/love-meter)
### See also
[math library](/reference/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)

View File

@ -34,10 +34,6 @@ Use [show string](/reference/basic/show-string) to display a string on the [LED
The parameter of `show string` specifies the string
### Lessons
[glowing pendulum](/lessons/glowing-pendulum), [zoomer](/lessons/zoomer), [temperature](/lessons/temperature)
### See also
[variables](/reference/variables/var), [string functions](/reference/types/string-functions), [Number](/reference/types/number), [show string](/reference/basic/show-string)

View File

@ -30,10 +30,6 @@ You can use the assignment operator with variables of
every [type](/reference/types). A *type* is which kind of thing
a variable can store, like a number or string.
### Lessons
[rotation animation](/lessons/rotation-animation)
### See also
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -81,10 +81,6 @@ if (led.brightness() > 128) {
* You can use the default variable names if you'd like, however, it's best to use descriptive variable names. To change a variable name in the editor, select the down arrow next to the variable and then click "new variable".
### Lessons
[glowing pendulum](/lessons/glowing-pendulum), [love meter](/lessons/love-meter), [temperature](/lessons/temperature), [zoomer](/lessons/zoomer)
### See also
[types](/reference/types), [assignment operator](/reference/variables/assign)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 33 KiB

BIN
docs/static/mb/projects/all10.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -2,7 +2,7 @@
### ~avatar avatar
The Uploader **automatically** deploys .hex files to all BBC micro:bit connected to your computer.
The Uploader **automatically** deploys .hex files to all micro:bits connected to your computer.
## [DOWNLOAD](https://www.pxt.io/microbit-uploader.zip)
@ -12,8 +12,8 @@ The Uploader **automatically** deploys .hex files to all BBC micro:bit connected
### Works with any browser!
The uploader monitors your Downloads folder looking for any .hex file being download.
When it detects a new .hex file, the uploader tries to copy it to all connected BBC micro:bits (it copies it to the MICROBIT drives).
The uploader monitors your Downloads folder looking for any .hex file that has been downloaded (saved from the browser).
When it detects a new .hex file, the uploader tries to copy it to all MICROBIT drives.
That's it!
![](/static/uploader/tooltip.png)

View File

@ -0,0 +1 @@
# Bluetooth services

View File

@ -0,0 +1,15 @@
#include "pxt.h"
#include "MESEvents.h"
using namespace pxt;
//% color=#0082FB weight=2
namespace bluetooth {
/**
* Starts the Bluetooth IO pin service
*/
//% help=bluetooth/io-pin-service
//% blockId=bluetooth-io-pin-service block="bluetooth io pin service"
void startIOPinService() {
new MicroBitIOPinService(*uBit.ble, uBit.io);
}
}

5
libs/microbit-bluetooth/enums.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
// Auto-generated. Do not edit.
declare namespace bluetooth {
}
// Auto-generated. Do not edit. Really.

View File

@ -0,0 +1,24 @@
{
"name": "microbit-bluetooth",
"description": "Bluetooth services",
"files": [
"README.md",
"enums.d.ts",
"shims.d.ts",
"bluetooth.cpp"
],
"public": true,
"dependencies": {
"microbit": "file:../microbit"
},
"yotta": {
"config": {
"microbit-dal": {
"bluetooth": {
"enabled": 1
}
}
}
},
"installedVersion": "bpcjjs"
}

16
libs/microbit-bluetooth/shims.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
// Auto-generated. Do not edit.
//% color=#0082FB weight=2
declare namespace bluetooth {
/**
* Starts the Bluetooth IO pin service
*/
//% help=bluetooth/io-pin-service
//% blockId=bluetooth-io-pin-service block="bluetooth io pin service" shim=bluetooth::startIOPinService
function startIOPinService(): void;
}
// Auto-generated. Do not edit. Really.

View File

@ -204,7 +204,7 @@ namespace devices {
/**
* Registers code to run when the device notifies about a change of signal strength.
* @param body TODO
* @param body Code run when the signal strength changes.
*/
//% weight=23 help=devices/on-signal-strength-changed
//% blockId=devices_signal_strength_changed_event block="on signal strength changed" icon="\uf012"
@ -213,4 +213,3 @@ namespace devices {
registerWithDal(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, body);
}
}

View File

@ -57,7 +57,7 @@ declare namespace devices {
/**
* Registers code to run when the device notifies about a change of signal strength.
* @param body TODO
* @param body Code run when the signal strength changes.
*/
//% weight=23 help=devices/on-signal-strength-changed
//% blockId=devices_signal_strength_changed_event block="on signal strength changed" icon="\uf012" shim=devices::onSignalStrengthChanged

View File

@ -29,8 +29,8 @@ namespace basic {
/**
* Draws an image on the LED screen.
* @param leds TODO
* @param interval TODO
* @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing
*/
//% help=basic/show-leds
//% weight=95 blockGap=8
@ -77,8 +77,8 @@ namespace basic {
/**
* Shows a sequence of LED screens as an animation.
* @param leds TODO
* @param interval TODO
* @param leds pattern of LEDs to turn on/off
* @param interval time in milliseconds between each redraw
*/
//% help=basic/show-animation imageLiteral=1 async
void showAnimation(ImageLiteral leds, int interval = 400) {
@ -87,7 +87,7 @@ namespace basic {
/**
* Draws an image on the LED screen.
* @param leds TODO
* @param leds pattern of LEDs to turn on/off
*/
//% help=basic/plot-leds weight=80
void plotLeds(ImageLiteral leds) {
@ -104,7 +104,7 @@ namespace basic {
/**
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body TODO
* @param body code to execute
*/
//% help=basic/forever weight=55 blockGap=8
//% blockId=device_forever block="forever" icon="\uf01e"

View File

@ -159,7 +159,7 @@ namespace music {
* Change the tempo by the specified amount
* @param bpm The change in beats per minute to the tempo, eg: 20
*/
//% help=music/tempo weight=39
//% help=music/change-tempo weight=39
//% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8
export function changeTempoBy(bpm: number): void {
setTempo(beat(BeatFraction.Whole) + bpm);
@ -169,7 +169,7 @@ namespace music {
* Sets the tempo to the specified amount
* @param bpm The new tempo in beats per minute, eg: 120
*/
//% help=music/tempo weight=38
//% help=music/set-tempo weight=38
//% blockId=device_set_tempo block="set tempo to (bpm)|%value"
export function setTempo(bpm: number): void {
init();

Some files were not shown because too many files have changed in this diff Show More