Compare commits

...

87 Commits

Author SHA1 Message Date
f3bfe3d94e 0.2.132 2016-05-26 11:15:56 -07:00
ed54ace797 Bump pxt-core to 0.2.141 2016-05-26 11:15:16 -07:00
0648e80131 added serial.redirect 2016-05-26 11:07:09 -07:00
ce9a83ff28 0.2.131 2016-05-26 09:15:26 -07:00
54439bba4d Bump pxt-core to 0.2.140 2016-05-26 09:15:22 -07:00
23a581c899 added rock-paper-scissors page 2016-05-26 09:15:10 -07:00
3f8fa4b05b 0.2.130 2016-05-25 10:53:55 -07:00
53ab8651bd Bump pxt-core to 0.2.139 2016-05-25 10:53:52 -07:00
87300be648 updated starter template 2016-05-24 22:18:33 -07:00
d0a7df7f36 0.2.129 2016-05-24 21:57:47 -07:00
1c8fa5eab6 move pins->map up in block list 2016-05-24 21:39:57 -07:00
d8c2d697b1 Merge pull request #75 from gbaman/master
Add few more radio documentation pages
2016-05-24 21:21:00 -07:00
2ede815535 Add write-value-to-serial documentation 2016-05-25 02:58:27 +01:00
a67f16a860 Deleted redundant paragraph. 2016-05-24 18:27:14 -07:00
819ab9aa9a Add receive-string documentation page 2016-05-25 02:23:33 +01:00
318ffde27f Add send-string documentation page 2016-05-25 01:53:13 +01:00
525e59ae4f Heavy rewrite; added Fahrenheit example too for US. 2016-05-24 17:51:10 -07:00
ab087b4afa Add set-transmit-power documentation page 2016-05-25 01:40:01 +01:00
3b8ae69a6c Rewrite of text and examples. 2016-05-24 15:36:04 -07:00
8de6605112 0.2.128 2016-05-24 14:32:27 -07:00
daea493dcb Bump pxt-core to 0.2.138 2016-05-24 14:32:11 -07:00
b290692334 using pxt constant to find binary .hex 2016-05-24 14:06:25 -07:00
f25f295d0c 0.2.127 2016-05-24 13:03:06 -07:00
5fd691ef92 Bump pxt-core to 0.2.137 2016-05-24 13:03:04 -07:00
67c8753315 Updating loop docs 2016-05-24 12:30:31 -07:00
9d405afde0 0.2.126 2016-05-24 11:41:37 -07:00
b05c8ebd56 Bump pxt-core to 0.2.136 2016-05-24 11:41:35 -07:00
b69156a12e adding target compile service configuration 2016-05-24 09:46:33 -07:00
961e2cb6e9 Simple language rewrite. Needs new code example; legacy one broken. 2016-05-23 18:02:40 -07:00
924d31a211 Simple language for short topic. 2016-05-23 17:21:36 -07:00
8721b54679 Pretty thoroughly rewritten in simple language. 2016-05-23 16:21:08 -07:00
e99292d008 Minor clarification 2016-05-23 14:46:11 -07:00
cc1ed10efb pics for the 10 activities 2016-05-23 17:39:44 -04:00
b48c11d380 Simpler language; added another (simpler) example. 2016-05-23 13:41:01 -07:00
3f1602f2c0 Simpler language, more interesting example (running time was always 0). 2016-05-23 12:45:14 -07:00
324fd45fb6 Rewriting play-tone for correctness & clarity. 2016-05-23 11:50:08 -07:00
d1a3892eab Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-21 08:25:16 -07:00
28d28eb67f Rewrite text, code sample. 2016-05-20 18:33:31 -07:00
a67164d5e6 Making another topic easier to understand. 2016-05-20 16:05:45 -07:00
86b35ae88d Absolutely necessary tiny tweak. 2016-05-20 15:36:37 -07:00
919c8fdfca Rewrite in simple English, debug the examples. 2016-05-20 15:33:15 -07:00
4abdb28a59 More simple English docs. 2016-05-20 13:24:27 -07:00
21361708ec Rest of Basic in simple English. Reconsider some code samples? 2016-05-20 13:09:18 -07:00
4e56342e52 updated docs 2016-05-20 05:40:54 -07:00
7273354944 support for 3g/6g gestures 2016-05-20 05:39:44 -07:00
9c96591edd 0.2.125 2016-05-19 23:21:16 -07:00
4f38658d74 Bump pxt-core to 0.2.131 2016-05-19 23:21:14 -07:00
6329a79ce1 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-19 23:19:17 -07:00
befbdd32cc Four rewrites of basic.* API pages in simple English. 2016-05-19 16:50:02 -07:00
44688ee5d5 missing simulator function for serial 2016-05-19 14:50:02 -07:00
cc36bae97d Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-19 13:56:28 -07:00
c65bdb34af various docs updates 2016-05-19 13:56:24 -07:00
21f7ef9b55 Simplified (but not oversimplified) show-string docs. Proposed new reference format. 2016-05-19 13:49:26 -07:00
d7250d54f8 Simplified (but not oversimplified) show-string docs. Proposed new reference format. 2016-05-19 13:46:02 -07:00
9a36a2fc05 removing serial event (not supported in DAL) 2016-05-19 13:39:28 -07:00
539357237f 0.2.124 2016-05-19 12:37:54 -07:00
35d59da17e Bump pxt-core to 0.2.130 2016-05-19 12:37:52 -07:00
0b226bc9aa updated category colors theme 2016-05-19 11:59:57 -07:00
f2bab5d122 missing async annotation on serial 2016-05-19 10:53:48 -07:00
6e6a98559c updated setup instructions 2016-05-19 10:34:24 -07:00
217fce953d Table of contents proof of concept 2016-05-18 15:57:43 -07:00
bfac2910da tentative serial fix for #66 2016-05-18 11:57:10 -07:00
5962c28b0e Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-18 11:30:38 -07:00
d3509a6254 Test docs tweak 2016-05-18 11:28:15 -07:00
df91bf234c adding side menu 2016-05-18 11:15:00 -07:00
2a46935f62 better startup instructions 2016-05-18 09:18:14 -07:00
5e024c6f23 added test package 2016-05-17 10:42:44 -07:00
28b3d823b2 0.2.123 2016-05-17 10:28:46 -07:00
b7c9bc7978 fixing test suite 2016-05-17 10:28:26 -07:00
52b2ee3f4c 0.2.122 2016-05-17 09:59:06 -07:00
263cc25633 updated docs 2016-05-17 09:58:51 -07:00
2e3d875b7d added serial events 2016-05-17 09:36:01 -07:00
7704ad9f8d doc updates 2016-05-17 09:35:55 -07:00
845d7a004c updated docs 2016-05-16 22:18:58 -07:00
1cf070d649 changed starting template 2016-05-16 22:04:41 -07:00
24420a2cc4 0.2.121 2016-05-16 21:52:35 -07:00
2f8b61998b bringing back triangles / logo on simulator 2016-05-16 21:48:54 -07:00
af38071c6a 0.2.120 2016-05-16 16:25:04 -07:00
89f09c7f35 added pins->on pulsed 2016-05-16 16:24:44 -07:00
a667467bbd 0.2.119 2016-05-13 06:25:57 -07:00
ada2583e17 removing browserconfig.xml / favicon.ico until cloud supports it 2016-05-13 06:18:15 -07:00
c04538313d 0.2.118 2016-05-13 05:44:48 -07:00
1039dc560e Bump pxt-core to 0.2.129 2016-05-13 05:44:46 -07:00
957c7ad848 0.2.117 2016-05-13 05:08:07 -07:00
5e7351a481 Bump pxt-core to 0.2.127 2016-05-13 05:08:05 -07:00
f0c089373b updated mobile icons 2016-05-13 04:55:28 -07:00
879a85bdbb exposing i2c blocks in pins 2016-05-13 03:38:52 -07:00
109 changed files with 1426 additions and 365 deletions

4
.gitignore vendored
View File

@ -1,9 +1,11 @@
node_modules
yotta_modules
yotta_targets
built
typings
tmp
temp
projects
projects/**
win10/app/bin
win10/app/bld
win10/*.opendb

View File

@ -7,21 +7,39 @@ This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) usin
[![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit)
# Getting started
## Local server
Please follow instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
### Setup
The following commands are a 1-time setup after synching the repo on your machine.
* install the PXT command line
```
npm install -g pxt
```
* install the dependencies
```
npm install
```
### Running
Run this command to open a local web server:
```
pxt serve
```
To make sure you're running the latest tools, run
```
npm update
```
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
## Universal Windows App
The Windows 10 app is a [Universal Windows Hosted Web App](https://microsoftedge.github.io/WebAppsDocs/en-US/win10/CreateHWA.htm)
that wraps m.pxt.io and provides additional features.
### Sideloading
* Open Windows **settings** and search for **Developer options**
* Enable the developer mode.
* Find the latest build under ``win10/app/AppPackages/latest`` and run the ``Add-AppDevPackage.ps1`` PowerShell script (mouse right-click, then `run with PowerShell`)
### Building
* Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed.

View File

@ -1,8 +1,8 @@
/// <reference path="../node_modules/pxt-core/built/pxt.d.ts"/>
import * as fs from 'fs';
import * as path from 'path';
import * as child_process from 'child_process';
import * as fs from "fs";
import * as path from "path";
import * as child_process from "child_process";
let writeFileAsync: any = Promise.promisify(fs.writeFile)
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
@ -13,10 +13,10 @@ export function deployCoreAsync(res: ts.pxt.CompileResult) {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to")
} else {
console.log("copy microbit.hex to " + drives.join(", "))
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
}
return Promise.map(drives, d =>
writeFileAsync(d + "microbit.hex", res.outfiles["microbit.hex"])
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
.then(() => {
console.log("wrote hex file to " + d)
}))

View File

@ -26,7 +26,7 @@ input.onButtonPressed(Button.B, () => {
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) 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](https://www.microbit.co.uk/partners).
The micro:bit provides a fun introduction to programming and making switch on, program it to do something fun wear it, customize it.
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.
## Blocks or JavaScript

View File

@ -1,8 +1,35 @@
# Documentation
Welcome to the documentation.
```sim
basic.forever(() => {
basic.showString("DOCS ");
})
input.onButtonPressed(Button.A, () => {
led.stopAnimation();
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
input.onButtonPressed(Button.B, () => {
led.stopAnimation();
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .`);
});
```
* **[getting started](/getting-started)**
* Browse the [API reference](/reference)
* Learn more about the [device](/device)
* Get started with [lessons](/lessons)
* Learn about [libraries](/libraries) (possibly using C++)
* Follow up with the [release notes](/release-notes)
### Developers
* Learn about [packages](/packages) (possibly using C++ or ARM thumb)

View File

@ -2,7 +2,7 @@
Are you ready to build cool BBC micro:bit programs? For each challenge, reorder the blocks to recreate the program.
* If you haven't done so, open [https://m.pxt.io](/) and create a new **Blocks Editor** project
## Open [https://m.pxt.io](/) and create a new **Blocks Editor** project
## Basic
@ -28,10 +28,9 @@ To transfer your code to the BBC micro:bit,
### Show animation Forever
Show one image after the other to create an animation.,
Show one image after the other to create an animation by snapping them together.
Reorder the blocks to make the micro:bit show a happy, then unhappy face.
```shuffle
```blocks
basic.showLeds(`
. . . . .
. # . # .
@ -48,6 +47,7 @@ Reorder the blocks to make the micro:bit show a happy, then unhappy face.
`)
```
### Repeat forever
Use the ``forever`` block to repeat your code and have a continuous animation.

View File

@ -1,23 +0,0 @@
# microbit Reference
```namespaces
basic.showNumber(0);
input.onButtonPressed(Button.A, () => {
});
led.plot(0, 0);
music.playTone(0, 0);
game.addScore(1);
images.createImage(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`);
pins.digitalReadPin(DigitalPin.P0);
serial.writeValue(x, 0);
control.inBackground(() => {
});
```

9
docs/open-source.md Normal file
View File

@ -0,0 +1,9 @@
# Open Source
The editor is open source on GitHub under the MIT license. Contributions are welcome, please check our GitHub repos.
### Repos
* [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

15
docs/projects.md Normal file
View File

@ -0,0 +1,15 @@
# Projects
### @short Projects
### ~column
## Beginner
* [Rock Paper Scissors](/projects/rock-paper-scissors)
### ~
### ~column

View File

@ -0,0 +1,162 @@
# rock paper scissors
### ~avatar avatar
### @video td/videos/rock-paper-scissors-0
In this project, you will build a rock-paper-scissor game with the BBC micro:bit
### ~
## Materials needed
* your BBC micro:bit, that's it!
## 1
We want the micro:bit to choose rock, paper, or scissors when it is shaken. Let's begin by creating an on shake condition so the micro:bit will run code when it is shaken.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
Next, create a variable and store pick random number from 0 to 2. On shake, a number will be randomly picked from 0-2. We will randomly display an image based on the random number returned.
```blocks
input.onGesture(Gesture.Shake, () => {
let img = Math.random(3)
})
```
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 0. We can help the micro:bit randomly decide which image to use by pick random.
The micro:bit will randomly pick the image to display with show LEDs and the ``pick random`` block.
```blocks
input.onGesture(Gesture.Shake, () => {
let img = Math.random(3)
if (img == 2) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
}
})
```
## 2
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 1.
We can help the micro:bit randomly decide which image to use by pick random.
The micro:bit will randomly pick the image to display with show LEDs and the pick random function.
### ~avatar avatar
Click on the blue gearwheel to open the ``if`` editor. Drag and drop the ``else if`` block in the ``if`` block to add it.
### ~
```blocks
input.onGesture(Gesture.Shake, () => {
let img = Math.random(3)
if (img == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (img == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
}
})
```
## 3
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is not equal to 0 and not equal to 1.
We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function.
```blocks
input.onGesture(Gesture.Shake, () => {
let img = Math.random(3)
if (img == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (img == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
. . . # #
# # . # .
. . # . .
# # . # .
. . . # #
`)
}
})
```
Your game is ready!
## 4
When the button ``A`` is pressed, increment the score by 1. You can select ``Game`` drawer then add ``change score by 1``.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```
## 5
After incrementing the score, display the total number of wins you have.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
basic.showString("WINS:")
basic.showNumber(game.score())
})
```
## 6
You have successfully tracked and displayed the number of wins on the micro:bit! However, what about losses?
Use the Game drawer to change score by -1 when button `B` is pressed. Here are all the blocks you will need:
```shuffle
input.onButtonPressed(Button.B, () => {
game.addScore(-1)
basic.showString("LOSSES:")
basic.showNumber(game.score())
})
```

View File

@ -9,8 +9,9 @@ basic.showNumber(0);
input.onButtonPressed(Button.A, () => {
});
led.plot(0, 0);
music.playTone(0, 0);
led.plot(0, 0);
radio.sendNumber(0);
game.addScore(1);
images.createImage(`
. . . . .

View File

@ -8,7 +8,7 @@ basic.clearScreen()
### Example: vanishing heart
The following code displays a heart on the screen and then turns off all the LED lights using `clear screen`:
The following code shows a heart on the screen and then turns off all the LED lights using `clear screen`:
```blocks
basic.showLeds(`

View File

@ -1,6 +1,7 @@
# Forever
Repeat code [in the background](/reference/control/in-background) forever.
Keep running part of a program
[in the background](/reference/control/in-background).
```sig
basic.forever(() => {
@ -9,7 +10,9 @@ basic.forever(() => {
### Example: compass
The following example constantly checks the [compass heading](/reference/input/compass-heading) and updates the screen with the direction.
The following example constantly checks the
[compass heading](/reference/input/compass-heading)
and updates the screen with the direction.
```blocks
basic.forever(() => {
@ -30,7 +33,9 @@ basic.forever(() => {
### Example: counter
The following example continually shows the current value of a global variable:
The following example keeps showing the [number](/reference/types/number) stored in a global variable.
When you press button `A`, the number gets bigger.
You can use a program like this to count things with your BBC micro:bit.
```blocks
let num = 0
@ -42,9 +47,12 @@ input.onButtonPressed(Button.A, () => {
})
```
### Contention for the LED display
### Competing for the LED screen
If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example:
If different parts of a program are each trying
to show something on the LED screen at the same time,
you may get unexpected results.
Try this on your micro:bit:
```blocks
basic.forever(() => {

View File

@ -1,6 +1,7 @@
# Pause
Pause program execution for the specified number of milliseconds. This function is helpful when you need to slow down your program's execution.
Pause the program for the number of milliseconds you say.
You can use this function to slow your program down.
```sig
basic.pause(400)
@ -8,11 +9,13 @@ basic.pause(400)
### Parameters
* ``ms`` - the number of milliseconds that you want to pause (100 = 1/10 second, 1000 milliseconds = 1 second)
* ``ms`` is the number of milliseconds that you want to pause (100 milliseconds = 1/10 second, and 1000 milliseconds = 1 second).
### Example: diagonal line
The following example code turns on LED `0, 0` thru `4, 4`, pausing 500 milliseconds after each LED. Without `pause`, the code would run so fast that you wouldn't see each individual LED turning on.
This example draws a diagonal line by turning on LED `0, 0` (top left) through LED `4, 4` (bottom right).
The program pauses 500 milliseconds after turning on each LED.
Without `pause`, the program would run so fast that you would not have time to see each LED turning on.
```blocks
for (let i = 0; i < 5; i++) {

View File

@ -1,6 +1,6 @@
# Show Animation
Show a series of image frames on the [LED screen](/device/screen), pausing the specified time after each frame.
Show a group of image frames (pictures) one after another on the [LED screen](/device/screen). It pauses the amount of time you tell it after each frame.
```sig
basic.showAnimation(`
@ -14,10 +14,14 @@ basic.showAnimation(`
### Parameters
* `leds` - [String](/reference/types/string); a series of LED on/off states
* `interval` - [Number](/reference/types/number); the number of milliseconds to pause after each image frame
* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off, in groups one after another.
* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds to pause after each image frame.
### Show a series of image frames
### Example: Animating a group of image frames
In this animation, each row is 15 spaces wide because
there are three frames in the animation, and each frame is
five spaces wide, just like the screen on the BBC micro:bit.
```
basic.showAnimation(`
@ -31,13 +35,17 @@ basic.showAnimation(`
### ~hint
If the series of images appear too fast, increase the value of the *interval* parameter.
If the animation is too fast, make `interval` bigger.
### ~
### Example: animating frames
### Example: animating frames with a pause
The following example creates an image with six frames and then shows each frame o the screen, pausing 500 milliseconds after each frame:
This example shows six frames on the screen, pausing 500 milliseconds after each frame.
In this animation, each row is 30 spaces wide because
there are six frames in the animation, and each frame is
five spaces wide, just like the screen.
```
basic.showAnimation(`
@ -51,7 +59,7 @@ basic.showAnimation(`
### ~hint
Use [forever](/reference/basic/forever) to continually repeat an animation
Use [forever](/reference/basic/forever) to show an animation over and over.
### ~

View File

@ -15,12 +15,13 @@ basic.showLeds(`
### Parameters
* ``leds`` - a series of LED on/off states that form an image (see steps below)
* (optional) ``ms`` - [Number](/reference/types/number) - time to wait after displaying image. In blocks, ``ms`` is 400 by default.
* `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.
### Example - Block Editor
### Example
1. Open the `basic` category and select the `show leds` blocks.
Open the `basic` card in the Block Editor and select the `show leds` blocks.
```blocks
basic.showLeds(`
@ -33,7 +34,7 @@ basic.showLeds(`
)
```
In JavaScript, the led off is represented by a `.` and the led on by a `#` character.
If you are programming in JavaScript, `#` means an LED that is turned on and `.` means an LED that is turned off.
### Lessons

View File

@ -1,6 +1,6 @@
# Show Number
Show a number on the [LED screen](/device/screen), one digit at a time (scrolling from left to right)
Show a number on the [LED screen](/device/screen). It will slide left if it has more than one digit.
~~~~sig
basic.showNumber(2, 150)
@ -8,18 +8,18 @@ basic.showNumber(2, 150)
### Parameters
* value - a [Number](/reference/types/number)
* (optional) interval (ms) - [Number](/reference/types/number); the time (in milliseconds) before scrolling by one LED; the larger the number, the slower the scroll
* `value` is a [Number](/reference/types/number).
* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the `value` left by one LED each time. Bigger intervals make the sliding slower.
### ~
### Examples:
To display the number 10:
To show the number 10:
~~~~blocks
basic.showNumber(10)
~~~~
To display the number stored in the `x` variable:
To show the number stored in a variable:
~~~~blocks
let x = 1
@ -28,19 +28,19 @@ basic.showNumber(x)
### Example: count to 5
This example uses a [for](/reference/loops/for) loop to show numbers ``1`` through ``5`` on the screen:
This example uses a [for](/reference/loops/for) loop to show numbers ``0`` through ``5`` on the screen:
~~~~blocks
for (let i = 0; i < 5; i++) {
basic.showNumber(i + 1)
for (let i = 0; i < 6; i++) {
basic.showNumber(i)
basic.pause(200)
}
~~~~
### Other show functions
* use [show string](/reference/basic/show-string) to show a string on the screen
* use [show animation](/reference/basic/show-animation) to show a series of images on the screen
* 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

View File

@ -1,6 +1,6 @@
# Show String
Show a string on the [LED screen](/device/screen) one character at a time (scrolling from left to right).
Show a number on the [LED screen](/device/screen). It will slide left if it is bigger than the screen.
```sig
basic.showString("Hello!")
@ -8,18 +8,18 @@ basic.showString("Hello!")
### Parameters
* `text` - a [String](/reference/types/string)
* (optional) `ms` - [Number](/reference/types/number); the time (in milliseconds) before scrolling left by one LED; the larger the number, the slower the scroll
* `text` is a [String](/reference/types/string). It can contain letters, numbers, and punctuation.
* `ms` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the [String](/reference/types/string) left by one LED each time. Bigger intervals make the sliding slower.
### Examples:
To display Hello:
To show the word **Hello**:
```blocks
basic.showString("Hello")
```
To display the content of a string variable:
To show what is stored in a [String](/reference/types/string) variable:
```blocks
let s = "Hi"
@ -28,8 +28,8 @@ basic.showString(s)
### Other show functions
* use [show number](/reference/basic/show-number) to show a number on the screen
* use [show animation](/reference/basic/show-animation) to show a series of images on the screen
* 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

View File

@ -1,6 +1,6 @@
# Button Is Pressed
Get the state of an input button. The micro:bit has two input buttons: A and B.
Check whether a button is pressed right now. The micro:bit has two buttons: button `A` and button `B`.
```sig
input.buttonIsPressed(Button.A);
@ -8,24 +8,26 @@ input.buttonIsPressed(Button.A);
### Parameters
* name - [String](/reference/types/string); input button "A", "B", or "A+B" (both input buttons)
* ``name`` is a [String](/reference/types/string). You should store `A` in it to check the left button, `B` to check the right button, or `A+B` to check both at the same time.
### Returns
* [Boolean](/reference/types/boolean) - `true` if pressed, `false` if not pressed
* [Boolean](/reference/types/boolean) that is `true` if the button you are checking is pressed, `false` if it is not pressed.
### Example
The following code uses an [if](/reference/logic/if) statement to run code, depending on whether or not the A button is pressed:
This program uses an [if](/reference/logic/if) to run
one part of the program if the `A` button is pressed, and
another part if it is not pressed.
```blocks
basic.forever(() => {
let pressed = input.buttonIsPressed(Button.A)
if (pressed) {
// this code runs if the A button is pressed
// this part runs if the A button is pressed
basic.showNumber(1, 150)
} else {
// this code runs if the A button is *not* pressed
// this part runs if the A button is *not* pressed
basic.showNumber(0, 150)
}
})

View File

@ -1,8 +1,14 @@
# Light Level
Gets the light level from ``0`` (dark) to ``255`` (bright). The light is measured by using various LEDs from the screen.
Find the light level (how bright or dark it is) where you are.
The light level ``0`` means darkness and ``255`` means bright light.
The BBC micro:bit measures the light around it by using some of the
LEDs on the [LED screen](/device/screen).
This function will return ``0`` on the first call to this method, a light reading will be available after the display has activated the light sensor for the first time.
The first time you use it, this function will say ``0``.
After that, it will say the real light level.
This is because the light sensor (the part that can find the light level)
has to be turned on first.
```sig
input.lightLevel();
@ -10,11 +16,26 @@ input.lightLevel();
### Returns
* [Number](/reference/types/number) - light level from ``0`` (dark) to ``255`` (bright).
* a [Number](/reference/types/number) that means a light level from ``0`` (dark) to ``255`` (bright).
### Example: show light level
When you press button `B` on the microbit, this
program shows the light level
on the [LED screen](/device/screen).
```blocks
input.onButtonPressed(Button.B, () => {
let level = input.lightLevel()
basic.showNumber(level)
})
```
### Example: chart light level
Use `plot bar chart` to visual the influence of various light source on the light level.
This program shows the light level with a [bar chart](/reference/led/plot-bar-graph) on the micro:bit screen.
If you carry the micro:bit around to different places with different light levels,
the bar chart will change.
```blocks
basic.forever(() => {

View File

@ -1,6 +1,9 @@
# On Button Pressed
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
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 button `A` or `B` is pressed, or `A` and `B` together.
When you are using this function in a web browser, click the buttons on the screen instead of the ones
on the BBC micro:bit.
```sig
input.onButtonPressed(Button.A, () => {})
@ -8,7 +11,8 @@ input.onButtonPressed(Button.A, () => {})
### Example: count button clicks
This example counts how many times the left or right input button is pressed. Each time a button is pressed, the global count variable is increased by 1 and displayed on the screen.
This example counts how many times you press the `A` button.
Each time you press the button, the [LED screen](/device/screen) shows the `count` variable getting bigger.
```blocks
let count = 0
@ -19,22 +23,29 @@ input.onButtonPressed(Button.A, () => {
})
```
### Example: roll a dice
### Example: roll dice
This example generates a random number when you press the B input button, and then displays a random die image:
This example shows a number from 1 to 6 when you press the `B` button.
```blocks
input.onButtonPressed(Button.B, () => {
let dice = Math.random(6)
let dice = Math.random(6) + 1
basic.showNumber(dice)
})
```
### ~hint
This program adds a `1` to `random(6)` so the numbers on the dice will come out right.
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)
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/reference/math/math)

View File

@ -1,6 +1,6 @@
# Running Time
Get the number of milliseconds elapsed since the script began. 1,000 milliseconds = 1 second.
Find how long it has been since the program started.
```sig
input.runningTime();
@ -8,15 +8,20 @@ input.runningTime();
### Returns
* [Number](/reference/types/number)
* the [Number](/reference/types/number) of milliseconds since the program started.
(One second is 1000 milliseconds.)
### Example: elapsed time
This code gets the elapsed time since the start of the program execution and displays it on the screen.
When you press button `B` on the microbit, this
program finds the number of milliseconds since the program started
and shows it on the [LED screen](/device/screen).
```blocks
let now = input.runningTime()
basic.showNumber(now)
input.onButtonPressed(Button.B, () => {
let now = input.runningTime()
basic.showNumber(now)
})
```
### Lessons

View File

@ -1,6 +1,7 @@
# Temperature
Get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit.
Find the temperature where you are. The temperature is measured in Celsius (metric).
The micro:bit can find the temperature nearby by checking how hot its computer chips are.
```sig
input.temperature();
@ -8,24 +9,48 @@ input.temperature();
### Returns
* [Number](/reference/types/number) - temperature in degree Celsius °C.
* a [Number](/reference/types/number) that means the Celsius temperature.
### How does it work?
The BBC micro:bit does not have a dedicated temperature sensor. Instead, the temperature provided is actually the temperature of the silicon die on the main CPU. As the processor generally runs cold though (it is a high efficiency ARM core), the temperature is a good approximation of the ambient temperature... you might warm up if you give the processor a lot of work to do though, and don't [sleep](/reference/basic/pause)!
The temperature sensor has a high precision, but isn't trimmed for accuracy. In other words, it can sense changes in temperature very well, but there may be (and probably is) base line offset. i.e. it might return 20 degrees when it's actually 17, but it would return 21 when it is 18 etc.
The BBC micro:bit checks how hot its CPU (main computer chip) is.
Because the micro:bit does not usually get very hot, the temperature of the CPU
is usually close to the temperature of wherever you are.
The micro:bit might warm up a little if you make it work hard, though!
### Example: micro:bit thermometer
The following example uses the `temperature` and the `show number` to display the room temperature.
The following example uses `temperature` and `show number` to show the temperature of the room.
```sig
```blocks
basic.forever(() => {
let temp = input.temperature()
basic.showNumber(temp)
})
```
### Example: Fahrenheit thermometer
This program measures the temperature using Fahrenheit degrees.
Fahrenheit is a way of measuring temperature that is commonly used in the United States.
To make a Celsius temperature into a Fahrenheit one, multiply the Celsius temperature by
1.8 and add 32.
```blocks
basic.forever(() => {
let c = input.temperature()
let f = (c * 1.8) + 32
basic.showNumber(f)
})
```
### ~hint
Try comparing the temperature your micro:bit shows to a real thermometer in the same place.
You might be able to figure out how much to subtract from the number the micro:bit
shows to get the real temperature. Then you can change your program so the micro:bit is a
better thermometer.
### ~
### Lessons

View File

@ -1,6 +1,6 @@
# Brightness
Set the brightness of the [LED screen](/device/screen).
Find how bright the [LED screen](/device/screen) is.
```sig
led.brightness();
@ -8,11 +8,11 @@ led.brightness();
### Returns
* [Number](/reference/types/number) - returns the LCD screen brightness as a number from 0 to 255. A return value of 255 means the screen brightness is at 100% and 127 is about 50% brightness.
* a [Number](/reference/types/number) that means how bright the screen is, from `0` (darkest) to `255` (brightest). For example, the number `127` means the screen is halfway bright.
### Example: maximum brightness
### Example: highest brightness
If the screen brightness is < 100%, the following code sets the brightness to 100% (255):
This program makes the screen completely bright if it is not that way already:
```blocks
if (led.brightness() < 255) {

View File

@ -1,6 +1,7 @@
# Plot Bar Graph
Displays a vertical bar graph based on the value and high value.
Displays a bar graph of the numbers you say.
A bar graph is a kind of chart that shows numbers as lines with different lengths.
```sig
led.plotBarGraph(2, 20);
@ -8,10 +9,18 @@ led.plotBarGraph(2, 20);
### Parameters
* value: [Number](/reference/types/number) , high : [Number](/reference/types/number) displays a vertical bar graph based on the value and high value
* `value` is a [Number](/reference/types/number) that means what you are measuring or trying to show. For example, if you are measuring the temperature of ice with the BBC micro:bit, `value` might be 0 because the temperature might be 0 degrees centigrade.
* `high` is a [Number](/reference/types/number) that means the highest possible number that the `value` parameter can be. This number is also the tallest that the lines in the bar chart can be.
### Example: chart acceleration
This program shows a bar graph of the [acceleration](/reference/input/acceleration)
in the `x` direction of the micro:bit.
The micro:bit's `x` direction is from left to right (or right to left).
The more you speed up moving the micro:bit in this direction,
the taller the lines in the bar graph will be,
until they are as tall as the parameter `high` says they can be.
```blocks
basic.forever(() => {
let a = input.acceleration(Dimension.X);

View File

@ -1,39 +1,9 @@
# Logic
[if](/reference/logic/if)
```blocks
if(true) {
}
```
[Boolean](/reference/types/boolean) values: *true*; *false*
```blocks
true
false
```
Boolean binary operators: *and* (conjunction); *or* (disjunction)
```blocks
```cards
if(true) {}
true;
true && false;
true || false;
```
Boolean negation operator
```blocks
!true
```
Comparison operators (=, !=, <, >, <=, >=)
```blocks
0 == 0;
1 !- 0;
0 < 1;
1 > 0;
0 <= 1;
1 >= 0;
!true;
1 != 0;
```

View File

@ -1,23 +1,26 @@
# If
Run code based on a condition.
### @parent blocks/language
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
### Block Editor
![](/static/mb/hourofcode-0.png)
```blocks
if(true) {
}
```
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
### Example: adjusting screen brightness
![](/static/mb/blocks/game-library/pic0.png)
```blocks
if(input.lightLevel()<100){
led.setBrightness(255);
}
```
If the screen [brightness](/reference/led/brightness) is `< 100`, this code sets the brightness to `255`:
If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`:
### Lessons

View File

@ -1,26 +1,8 @@
# Loops
Repeat code.
[for](/reference/loops/for)
```blocks
```cards
for(let i = 0;i<5;i++) {}
```
[repeat](/reference/loops/repeat)
![](/static/mb/blocks/contents-0.png)
[while](/reference/loops/while)
```blocks
for(let i = 1;i<5;i++) {}
while(true) {}
```
[forever](/reference/basic/forever)
```blocks
basic.forever(() => {})
```

View File

@ -1,20 +1,16 @@
# For
Repeat code a preset number of times.
### @parent blocks/language
Run part of the program the number of times you say.
Repeat code a fixed number of times.
### Example: Count to 4
### Block Editor
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
![](/static/mb/events-0.png)
The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times:
```
for (let k = 0; k < 4; k++) {
```blocks
for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}
```
@ -24,5 +20,5 @@ for (let k = 0; k < 4; k++) {
### See also
[while](/reference/loops/while), [if](/reference/logic/if)
[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,21 +1,16 @@
# Repeat
Repeat code a preset number of times.
Repeat code a fixed number of times.
Run part of the program the number of times you say.
### Block Editor
![](/static/mb/blocks/contents-0.png)
### Touch Develop
### Lessons
Touch Develop has no `repeat` loop. Instead you can used a for loop
[looper](/lessons/looper)
```
for (let i = 0; i < 5; i++) {
}
```
### See also
The loop above will repeat five (5) times.
[for](/reference/loops/for), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,23 +1,14 @@
# While
Repeat code in a loop while a condition is true.
### @parent blocks/language
Repeat code while a [Boolean](/reference/types/boolean) `condition` is true.
### ~hide
```blocks
while(true) {
}
```
let condition = false
```
### ~
### Block Editor
![](/static/mb/string-0.png)
The while loop has a *condition* that evaluates to a [Boolean](/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`.
@ -27,11 +18,13 @@ The condition is tested before any code runs. Which means that if the condition
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
// index is set to 4
![](/static/mb/blocks/var-10.png)
// subtract 1 from `index` each time through loop
```blocks
let index = 4;
while(index >= 0) {
led.plot(index, index);
index--;
}
```
### Lessons

View File

@ -1,10 +1,10 @@
# Play Tone
Plays a music tone through pin ``P0`` for the given duration.
Play a musical tone through pin ``P0`` of the micro:bit for as long as you say.
## Simulator
Simulation of this function is available in many, but not all browsers.
This function only works on the micro:bit and in some browsers.
```sig
music.playTone(440, 120)
@ -12,11 +12,14 @@ music.playTone(440, 120)
### Parameters
* `frequency` : [Number](/reference/types/number) - the frequency of the note (in Herz)
* `ms`: [Number](/reference/types/number) - the duration of the note (milliseconds)
* `Hz` is the [Number](/reference/types/number) of Hertz (the frequency, how high or low the tone is).
* `ms` is the [Number](/reference/types/number) of milliseconds that the tone lasts.
## Example
This example stores the musical note C in the variable `freq`.
Next, it plays that note for 1000 milliseconds (one second).
```blocks
let freq = music.noteFrequency(Note.C)
music.playTone(freq, 1000)

View File

@ -1,16 +1,16 @@
# Tempo
Returns the tempo in beats per minute.
Finds the tempo (speed of a piece of music).
```sig
music.tempo()
```
### Parameters
### Returns
* Returns : [Number](/reference/types/number) - returns the tempo in beats per minute
* a [Number](/reference/types/number) that means the bpm (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
### See also
[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone) , [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)
[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone), [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)

View File

@ -4,7 +4,7 @@ The micro:bit pins.
## How to work offline
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://codemicrobit.com/](https://codemicrobit.com/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://m.pxt.io/](https://m.pxt.io/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
## Save and load code using files

View File

@ -8,8 +8,14 @@ pins.digitalWritePin(DigitalPin.P0, 0);
pins.analogReadPin(AnalogPin.P0);
pins.analogWritePin(AnalogPin.P0, 1023);
pins.analogSetPeriod(AnalogPin.P0, 20000);
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
});
pins.pulseDuration();
pins.servoWritePin(AnalogPin.P0, 180);
pins.servoSetPulse(AnalogPin.P0, 1500);
pins.i2cReadNumber(0, NumberFormat.Int8LE);
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
pins.map(0, 0, 1023, 0, 4);
pins.analogPitch(0, 0);
pins.analogSetPitchPin(AnalogPin.P0);

View File

@ -4,13 +4,17 @@ Communicate data using radio packets
```cards
radio.sendNumber(0);
radio.sendNumbers(0, 0, 0, 0);
radio.sendValue("data", 0);
radio.sendString("");
radio.onDataReceived(() => {
});
radio.receiveNumber();
radio.receivedNumberAt(0);
radio.receiveString();
radio.receivedSignalStrength();
radio.setGroup(0);
radio.setTransmitPower(0);
radio.writeValueToSerial();
radio.setTransmitSerialNumber(true);
```

View File

@ -0,0 +1,67 @@
# Receive String
Reads the next radio packet if any and returns the first string.
## 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.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.receiveString()
```
### Return value
* the first [string](/reference/types/string) of the packet if any. ```""``` otherwise.
### Examples
Read the string broadcasted by other micro:bits and display it.
```blocks
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
});
```
A simple program to send whether you are happy, or sad over ```radio```, using the A or B button to select an emotion.
```blocks
let data: string = "";
input.onButtonPressed(Button.A, () => {
radio.sendString("H");
});
input.onButtonPressed(Button.B, () => {
radio.sendString("S");
});
radio.onDataReceived(() => {
data = radio.receiveString();
if ("H" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`);
} else if ("S" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`);
} else {
basic.showString("?");
}
});
```
### See also
[send string](/reference/input/send-string), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,33 @@
# Send String
Broadcasts a string data packet to other micro:bits connected via ``radio``.
## 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.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.sendString("Hello world!")
```
### Parameters
* msg - a string to be transmitted.
### Examples
Broadcasts the provided string to other micro:bits.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendString("Mr. Watson, come here, I want to see you.")
})
```
### See also
[receive string](/reference/radio/receive-string), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,38 @@
# Set Transmit Power
Sets the transmitter power for ``radio`` communications.
The power can be set to a value between 0 (-30dbm) and 7 (+4dbm).
## Range
At power level 7, in an open area without significant interference (coming from WiFi networks or other devices operating on the 2.4 GHz range), you can get a **range of over 70m**.
Indoors (or with additional interference), range will be significantly reduced.
## 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.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.setTransmitPower(1)
```
### Parameters
* ``power`` -- a [number](/reference/types/number) between ``0`` and ``7``.
### Example
Sets the transmitter power to full power at 7.
```blocks
radio.setTransmitPower(7)
```
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,45 @@
# Write Value To Serial
Writes the full data received data via ``radio`` to serial in JSON format.
**Note** - This method only works for [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value). It does not work for [send string](/reference/radio/send-string) (although a string can be sent with [send value](/reference/radio/send-value)).
## Data received format
The format for received data printed to serial is as follows
- [send number](/reference/radio/send-number) - ```{v:ValueSent,t:MicrobitTimeAlive,s:Unused}```
- [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.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.writeValueToSerial()
```
### Parameters
* None
### Examples
When ```radio``` data is received (after pressing A button on 2nd micro:bit), output temperature data to serial.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(input.temperature());
});
radio.onDataReceived(() => {
radio.writeValueToSerial();
});
```
Example output to serial when A button pressed:
```{v:27,t:323,s:0}```
### See also
[send number](/reference/radio/send-number), [send value](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -3,6 +3,9 @@
Reading and writing data over a serial connection.
```cards
serial.writeValue(x, 0);
serial.writeLine("");
serial.writeNumber(0);
serial.writeValue(x, 0);
serial.writeString("");
serial.readLine();
```

197
docs/reference/toc.md Normal file
View File

@ -0,0 +1,197 @@
acceleration
analog-pitch
analog-read-pin
analog-set-period
analog-set-pitch-pin
analog-write-pin
assign
boolean
brightness
button-is-pressed
change
change-score-by
change-tempo
change-var
clear
clear-screen
compass-heading
create-image
digital-read-pin
digital-write-pin
fade-in
fade-out
for
forever
game-library
game-over
if
image
in-background
light-level
magnetic-force
map
math
move
number
[on button pressed](/reference/input/on-button-pressed)
on-data-received
on-gamepad-button
on-gesture
on-pin-pressed
on-signal-strength-changed
pause
pin-is-pressed
pixel
play-tone
plot
plot-all
plot-bar-graph
plot-frame
plot-image
plot-leds
point
position
raise-alert-to
receive-number
receive-number
repeat
reports
reset
rest
ring-tone
rotation
running-time
score
screenshot
scroll-image
send-number
servo-set-pulse
servo-write-pin
set-brightness
set-display-mode
set-group
set-pixel
set-tempo
show-animation
show-frame
show-image
show-leds
show-number
show-string
signal-strength
start-countdown
stop-animation
string
tell-camera-to
tell-microphone-to
tell-remote-control-to
temperature
tempo
toggle
toggle-all
touching
turn
unplot
var
while
width
write-line
write-value

View File

@ -1,34 +1,34 @@
# Assignment Operator
Set the value for local and global variables.
Use an equals sign to make a [variable](/reference/variables/var) store the [number](/reference/types/number)
or [string](/reference/types/string) you say.
### @parent blocks/operators
When you use the equals sign to store something in a variable, the equals sign is called
an *assignment operator*, and what you store is called a *value*.
Set or change the value of a variable
### Storing numbers in variables
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
````blocks
let item = 0
let item = 5
basic.showNumber(item)
````
Use the assignment operator to set or change the value of a [variable](/reference/variables/var).
### Storing strings in variables
### Declare a variable
Declare a new *local* variable using the [variable](/reference/variables/var) statement and the assignment operator. Like this:
This program makes the variable `name` equal `Joe` and then shows it on the [LED screen](/device/screen).
````blocks
let num1 = 42;
let name = "Joe";
let name = "Joe"
basic.showString(name);
````
The variable's name is on the left of the assignment operator and the variable's value is on the right:
````blocks
let num1 = 42
````
### Notes
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
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

11
docs/release-notes.md Normal file
View File

@ -0,0 +1,11 @@
# Release notes
```sim
basic.forever(() => { basic.showString("RELEASE NOTES"); });
```
### May 2017
We're happy to announce [m.pxt.io](https://m.pxt.io), an Blocks/JavaScript editor for the [BBC micro:bit](https://www.microbit.co.uk).
The editor is [open source](/open-source) on GitHub. Send us your PR!

BIN
docs/static/favicon.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
docs/static/icons/apple-touch-icon.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
docs/static/icons/favicon-16x16.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

BIN
docs/static/icons/favicon-32x32.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

BIN
docs/static/icons/favicon-96x96.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

BIN
docs/static/icons/mstile-144x144.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 B

BIN
docs/static/icons/mstile-150x150.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B

BIN
docs/static/icons/mstile-310x150.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

BIN
docs/static/icons/mstile-310x310.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
docs/static/icons/mstile-70x70.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

59
docs/static/icons/safari-pinned-tab.svg vendored Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="319.000000pt" height="319.000000pt" viewBox="0 0 319.000000 319.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,319.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M145 2888 c-49 -17 -92 -55 -114 -101 -21 -43 -21 -46 -21 -1110 l0
-1067 40 0 40 0 0 -135 c0 -78 4 -135 9 -135 6 0 11 90 13 218 3 207 4 218 26
249 28 40 98 68 147 59 46 -9 102 -59 112 -99 5 -18 7 -127 5 -244 l-3 -212
-107 -4 -107 -3 120 0 120 1 3 158 3 158 142 -3 142 -3 3 -157 c1 -87 7 -158
12 -158 5 0 10 100 12 227 3 254 8 274 78 320 60 41 143 20 187 -46 22 -33 23
-41 23 -267 0 -149 4 -234 10 -234 6 0 10 60 10 160 l0 160 190 0 190 0 0
-161 c0 -104 3 -158 10 -154 6 4 10 93 10 233 0 207 2 230 20 259 40 67 112
88 182 54 78 -38 83 -53 86 -319 2 -135 7 -232 13 -232 5 0 9 68 9 160 l0 160
185 0 185 0 0 -154 c0 -93 4 -157 10 -161 7 -4 10 66 10 202 0 114 5 225 10
245 34 121 169 154 249 63 l31 -36 0 -234 c0 -145 4 -236 10 -240 7 -4 10 50
10 154 l0 161 150 0 150 0 0 -160 c0 -100 4 -160 10 -160 6 0 10 83 10 228 0
263 4 280 81 320 51 27 104 24 151 -9 54 -39 58 -58 58 -294 0 -137 4 -215 10
-215 6 0 10 53 10 140 l0 140 45 0 44 0 4 -77 c1 -43 4 435 5 1062 1 1092 1
1142 -17 1180 -24 53 -55 83 -105 106 -39 18 -96 19 -1466 18 -967 0 -1435 -4
-1455 -11z m1203 -635 l3 -73 -41 0 -40 0 0 76 0 75 38 -3 37 -3 3 -72z m587
2 l0 -70 -37 -3 -38 -3 0 76 0 76 38 -3 37 -3 0 -70z m-880 -280 l0 -70 -40 0
-40 0 -3 49 c-2 27 -1 60 3 73 5 21 11 24 43 21 l37 -3 0 -70z m589 59 c9 -23
7 -107 -3 -122 -5 -8 -22 -12 -42 -10 l-34 3 -3 59 c-2 32 -1 65 2 72 8 20 72
18 80 -2z m584 -61 l3 -73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4
l30 -3 3 -72z m-880 -5 l-3 -73 -35 0 -35 0 -3 73 -3 72 41 0 41 0 -3 -72z
m570 -5 l3 -73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z
m-1388 -363 l0 -180 -185 0 -185 0 0 180 0 180 185 0 185 0 0 -180z m2500 0
l0 -180 -180 0 -180 0 0 180 0 180 180 0 180 0 0 -180z m-1982 161 c9 -5 12
-27 10 -72 l-3 -64 -40 0 -40 0 -3 58 c-2 35 2 64 9 73 13 15 47 18 67 5z
m307 -66 l0 -70 -37 -3 -38 -3 0 76 0 76 38 -3 37 -3 0 -70z m873 -2 l3 -73
-41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m-590 -10 l3
-73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m280 68 c9
-5 12 -27 10 -72 l-3 -64 -40 0 -40 0 -3 64 c-3 67 4 81 43 81 11 0 26 -4 33
-9z m-568 -341 l0 -70 -40 0 -40 0 0 70 0 70 40 0 40 0 0 -70z m590 0 l0 -70
-40 0 -40 0 0 70 0 70 40 0 40 0 0 -70z m-292 -27 l3 -73 -41 0 -40 0 0 68 c0
38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m-3 -253 l0 -65 -42 -3 -43 -3 0 71
0 71 43 -3 42 -3 0 -65z"/>
<path d="M294 1689 c-25 -13 -54 -60 -54 -89 0 -55 47 -100 105 -100 42 0 75
20 94 57 15 29 14 49 -4 88 -24 49 -88 69 -141 44z"/>
<path d="M2779 1671 c-23 -23 -29 -38 -29 -71 0 -91 106 -135 171 -71 64 65
20 171 -71 171 -33 0 -48 -6 -71 -29z"/>
<path d="M845 836 c-88 -40 -106 -150 -34 -210 24 -20 41 -26 81 -26 44 0 54
4 84 34 32 32 40 56 34 111 -7 70 -99 121 -165 91z"/>
<path d="M1543 836 c-89 -40 -97 -178 -13 -221 66 -34 141 -10 175 55 19 37
19 64 -1 105 -28 60 -101 87 -161 61z"/>
<path d="M2255 836 c-86 -38 -105 -146 -35 -208 24 -23 40 -28 79 -28 143 0
173 188 38 239 -36 14 -45 13 -82 -3z"/>
<path d="M192 820 c-118 -72 -38 -255 98 -225 45 10 90 67 90 116 0 105 -99
163 -188 109z"/>
<path d="M2875 831 c-90 -40 -97 -169 -12 -221 122 -75 250 92 149 193 -32 31
-98 45 -137 28z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
docs/static/mb/activities/a1-display.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a10-watch.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
docs/static/mb/activities/a2-buttons.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a3-pins.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/static/mb/activities/a4-motion.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
docs/static/mb/activities/a5-compass.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/static/mb/activities/a6-music.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a8-network.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
docs/static/mb/activities/a9-radio.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -2,7 +2,7 @@
## Features
The Windows 10 App provides all the existing features of codemicrobit.com plus the following ones:
The Windows 10 App provides all the existing features of [m.pxt.io](https://m.pxt.io) plus the following ones:
* **auto-upload**: the compiled .hex file is automatically deployed to all connected BBC micro:bits
* **serial piping**: all serial data sent by connected BBC micro:bit is automatically imported and analyzed in the editor.
@ -12,7 +12,7 @@ The Windows 10 App provides all the existing features of codemicrobit.com plus t
The following instructions allow to side-load the Windows 10 app. This is required until the app is in the store.
* Search for “developer settings” in Windows 10 and put your computer in “Developer mode”.
* Download https://pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.**
* Download https://m.pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.**
* Open the extracted folder, right-click on `Add-AppDevPackage.ps1` and click on `Run with PowerShell`. Follow the prompts…
4) In order to communicate with the micro:bit via serial, you need to install the [ARM mbed driver](https://developer.mbed.org/handbook/Windows-serial-configuration).

View File

@ -0,0 +1,101 @@
{
"basic": "Provides access to basic micro:bit functionality.",
"basic.clearScreen": "Turn off all LEDs",
"basic.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.",
"basic.pause": "Pause for the specified time in milliseconds",
"basic.plotLeds": "Draws an image on the LED screen.",
"basic.showAnimation": "Shows a sequence of LED screens as an animation.",
"basic.showLeds": "Draws an image on the LED screen.",
"basic.showNumber": "Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.",
"basic.showString": "Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.",
"control": "Runtime and event utilities.",
"control.inBackground": "Schedules code that run in the background.",
"control.reset": "Resets the BBC micro:bit.",
"game": "A single-LED sprite game engine",
"game.addScore": "Adds points to the current score",
"game.gameOver": "Displays a game over animation.",
"game.score": "Gets the current score",
"game.setScore": "Sets the current score value",
"game.startCountdown": "Starts a game countdown timer",
"images": "Creation, manipulation and display of LED images.",
"images.createBigImage": "Creates an image with 2 frames.",
"images.createImage": "Creates an image that fits on the LED screen.",
"input": "Events and data from sensors",
"input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)",
"input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.",
"input.calibrate": "Obsolete, compass calibration is automatic.",
"input.compassHeading": "Get the current compass compass heading in degrees.",
"input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.",
"input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.",
"input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed",
"input.onGesture": "Attaches code to run when the screen is facing up.",
"input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onPinPressed": "Do something when a pin(``P0``, ``P1`` or both ``P2``) is pressed.",
"input.onScreenDown": "Attaches code to run when the screen is facing down.",
"input.onScreenUp": "Attaches code to run when the screen is facing up.",
"input.onShake": "Attaches code to run when the device is shaken.",
"input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.",
"input.rotation": "The pitch of the device, rotation along the ``x-axis``, in degrees.",
"input.runningTime": "Gets the number of milliseconds elapsed since power on.",
"input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.",
"input.temperature": "Gets the temperature in Celsius degrees (°C).",
"led": "Control of the LED screen.",
"led.brightness": "Get the screen brightness from 0 (off) to 255 (full bright).",
"led.fadeIn": "Fades in the screen display.",
"led.fadeOut": "Fades out the screen brightness.",
"led.plot": "Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
"led.plotAll": "Turns all LEDS on",
"led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.",
"led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.",
"led.screenshot": "Takes a screenshot of the LED screen and returns an image.",
"led.setBrightness": "Set the screen brightness from 0 (off) to 255 (full bright).",
"led.setDisplayMode": "Sets the display mode between black and white and greyscale for rendering LEDs.",
"led.stopAnimation": "Cancels the current animation and clears other pending animations.",
"led.toggle": "Toggles a particular pixel",
"led.toggleAll": "Inverts the current LED display",
"led.unplot": "Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
"music": "Generation of music tones through pin ``P0``.",
"music.beat": "Returns the duration of a beat in milli-seconds",
"music.changeTempoBy": "Change the tempo by the specified amount",
"music.noteFrequency": "Gets the frequency of a note.",
"music.playTone": "Plays a tone through pin ``P0`` for the given duration.",
"music.rest": "Rests (plays nothing) for a specified time through pin ``P0``.",
"music.ringTone": "Plays a tone through pin ``P0``.",
"music.setTempo": "Sets the tempo to the specified amount",
"music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.",
"pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...",
"pins.analogPitch": "Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.",
"pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.",
"pins.analogSetPitchPin": "Sets the pin used when using `pins->analog pitch`.",
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
"pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
"pins.i2cWriteNumber": "Write one number to a 7-bit I2C address.",
"pins.map": "Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.",
"pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.",
"pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulse`` handler.",
"pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.",
"pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).",
"radio": "Communicate data using radio packets",
"radio.onDataReceived": "Registers code to run when a packet is received over radio.",
"radio.receiveNumber": "Reads the next packet as a number from the radio queue.",
"radio.receiveString": "Reads the next packet as a string and returns it.",
"radio.receivedNumberAt": "Reads a number at a given index, between ``0`` and ``3``, from the packet received by ``receive number``. Not supported in simulator.",
"radio.receivedSignalStrength": "Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.\nnamespace=radio",
"radio.sendNumber": "Broadcasts a number over radio to any connected micro:bit in the group.",
"radio.sendString": "Broadcasts a number over radio to any connected micro:bit in the group.",
"radio.sendValue": "Broadcasts a name / value pair along with the device serial number\nand running time to any connected BBC micro:bit in the group.",
"radio.setGroup": "Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n@ param id the group id between ``0`` and ``255``, 1 eg",
"radio.setTransmitPower": "Change the output power level of the transmitter to the given value.",
"radio.setTransmitSerialNumber": "Set the radio to transmit the serial number in each message.",
"radio.writeValueToSerial": "Reads a value sent with `stream value` and writes it\nto the serial stream as JSON",
"serial": "Reading and writing data over a serial connection.",
"serial.readLine": "Reads a line of text from the serial port.",
"serial.writeLine": "Prints a line of text to the serial",
"serial.writeNumber": "Prints a numeric value to the serial",
"serial.writeString": "Sends a piece of text through Serial connection.",
"serial.writeValue": "Writes a ``name: value`` pair line to the serial."
}

View File

@ -1,6 +1,6 @@
/**
* Communicate data using radio packets
*/
//% color=270 weight=34
//% color=#E3008C weight=34
namespace radio {
}

View File

@ -72,7 +72,11 @@
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
"pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
"pins.i2cWriteNumber": "Write one number to a 7-bit I2C address.",
"pins.map": "Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.",
"pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.",
"pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulse`` handler.",
"pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.",
"pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).",
"serial": "Reading and writing data over a serial connection.",

View File

@ -4,7 +4,7 @@
/**
* Provides access to basic micro:bit functionality.
*/
//% color=190 weight=100
//% color=#0078D7 weight=100
namespace basic {
/**

View File

@ -141,7 +141,7 @@ namespace control {
* @param value Component specific code indicating the cause of the event.
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
*/
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
//% mode.defl=CREATE_AND_FIRE
void raiseEvent(int src, int value, EventCreationMode mode) {
MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
@ -150,11 +150,29 @@ namespace control {
/**
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler);
}
/**
* Gets the value of the last event executed on the bus
*/
//% blockId=control_event_value" block="event value"
//% weight=18
int eventValue() {
return pxt::lastEvent.value;
}
/**
* Gets the timestamp of the last event executed on the bus
*/
//% blockId=control_event_timestamp" block="event timestamp"
//% weight=19 blockGap=8
int eventTimestamp() {
return pxt::lastEvent.timestamp;
}
/**
* Gets a friendly name for the device derived from the its serial number

View File

@ -7,15 +7,15 @@ namespace control {
/**
* Returns the value of a C++ runtime constant
*/
//% weight=19 weight=19 blockId="control_event_source" block="%id"
export function eventSource(id: EventBusSource) : number {
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
export function eventSourceId(id: EventBusSource): number {
return id;
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=19 weight=19 blockId="control_event_value" block="%id"
export function eventValue(id: EventBusValue) : number {
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
export function eventValueId(id: EventBusValue): number {
return id;
}
@ -23,8 +23,7 @@ namespace control {
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code:number)
{
export function panic(code: number) {
}
/**

View File

@ -105,6 +105,16 @@ declare namespace basic {
*/
//% block="free fall"
FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL
/**
* Raised when a 3G shock is detected
*/
//% block="3g"
ThreeG = 8, // MICROBIT_ACCELEROMETER_EVT_3G
/**
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G
}
declare namespace input {
}
@ -262,8 +272,35 @@ declare namespace led {
P4 = 11, // MICROBIT_ID_IO_P4
P10 = 17, // MICROBIT_ID_IO_P10
}
declare enum PulseValue {
High = 4, // MICROBIT_PIN_EVT_PULSE_HI
Low = 5, // MICROBIT_PIN_EVT_PULSE_LO
}
declare namespace pins {
}
declare enum SerialPin {
P0 = 7, // MICROBIT_ID_IO_P0
P1 = 8, // MICROBIT_ID_IO_P1
P2 = 9, // MICROBIT_ID_IO_P2
P8 = 15, // MICROBIT_ID_IO_P8
P12 = 19, // MICROBIT_ID_IO_P12
P13 = 20, // MICROBIT_ID_IO_P13
P14 = 21, // MICROBIT_ID_IO_P14
P15 = 22, // MICROBIT_ID_IO_P15
P16 = 23, // MICROBIT_ID_IO_P16
}
declare enum BaudRate {
//% block=115200
BaudRate115200 = 115200,
//% block=9600
BaudRate9600 = 9600,
}
declare namespace serial {
}

View File

@ -21,19 +21,19 @@ enum LedSpriteProperty {
/**
* A single-LED sprite game engine
*/
//% color=176 weight=32
//% color=#008272 weight=32
namespace game {
var _score: number = 0;
var _life: number = 3;
var _startTime: number = 0;
var _endTime: number = 0;
var _isGameOver: boolean = false;
var _countdownPause: number = 0;
var _level: number = 1;
var _gameId: number = 0;
var img: Image;
var sprites: LedSprite[];
let _score: number = 0;
let _life: number = 3;
let _startTime: number = 0;
let _endTime: number = 0;
let _isGameOver: boolean = false;
let _countdownPause: number = 0;
let _level: number = 1;
let _gameId: number = 0;
let img: Image;
let sprites: LedSprite[];
/**
* Creates a new LED sprite pointing to the right.
* @param x sprite horizontal coordinate, eg: 2
@ -47,7 +47,7 @@ namespace game {
sprites.push(p);
plot();
return p;
}
}
/**
* Gets the current score
@ -394,7 +394,7 @@ namespace game {
}
plot();
}
/**
* Turn the sprite
* @param this TODO
@ -403,7 +403,7 @@ namespace game {
*/
//% weight=49
//% blockId=game_turn_sprite block="%sprite|turn %direction|by (°) %degrees"
public turn(direction : Direction, degrees: number) {
public turn(direction: Direction, degrees: number) {
if (direction == Direction.Right)
this.setDirection(this._dir + degrees);
else
@ -435,8 +435,8 @@ namespace game {
*/
//% weight=29
//% blockId=game_sprite_set_property block="%sprite|set %property|to %value" blockGap=8
public set(property : LedSpriteProperty, value:number) {
switch(property) {
public set(property: LedSpriteProperty, value: number) {
switch (property) {
case LedSpriteProperty.X: this.setX(value); break;
case LedSpriteProperty.Y: this.setY(value); break;
case LedSpriteProperty.Direction: this.setDirection(value); break;
@ -452,8 +452,8 @@ namespace game {
*/
//% weight=30
//% blockId=game_sprite_change_xy block="%sprite|change %property|by %value" blockGap=8
public change(property : LedSpriteProperty, value:number) {
switch(property) {
public change(property: LedSpriteProperty, value: number) {
switch (property) {
case LedSpriteProperty.X: this.changeXBy(value); break;
case LedSpriteProperty.Y: this.changeYBy(value); break;
case LedSpriteProperty.Direction: this.changeDirectionBy(value); break;
@ -461,15 +461,15 @@ namespace game {
case LedSpriteProperty.Blink: this.changeBlinkBy(value); break;
}
}
/**
* Gets a property of the sprite
* @param property the name of the property to change
*/
//% weight=28
//% blockId=game_sprite_property block="%sprite|%property"
public get(property : LedSpriteProperty) {
switch(property) {
public get(property: LedSpriteProperty) {
switch (property) {
case LedSpriteProperty.X: return this.x();
case LedSpriteProperty.Y: return this.y();
case LedSpriteProperty.Direction: return this.direction()
@ -681,7 +681,7 @@ namespace game {
function init(): void {
if (img == null) {
img = images.createImage(
`0 0 0 0 0
`0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

View File

@ -3,7 +3,7 @@
/**
* Creation, manipulation and display of LED images.
*/
//% color=45 weight=31
//% color=#5C2D91 weight=31
namespace images {
/**
* Creates an image that fits on the LED screen.

View File

@ -94,7 +94,17 @@ enum class Gesture {
* Raised when the board is falling!
*/
//% block="free fall"
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL,
/**
* Raised when a 3G shock is detected
*/
//% block="3g"
ThreeG = MICROBIT_ACCELEROMETER_EVT_3G,
/**
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = MICROBIT_ACCELEROMETER_EVT_6G
};
//% color=300 weight=99
@ -104,7 +114,7 @@ namespace input {
* @param button TODO
* @param body TODO
*/
//% help=input/on-button-pressed weight=85
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
void onButtonPressed(Button button, Action body) {
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
@ -114,9 +124,13 @@ namespace input {
* Attaches code to run when the screen is facing up.
* @param body TODO
*/
//% help=input/on-gesture weight=84
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(4);
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
uBit.accelerometer.setRange(8);
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
}

View File

@ -1,7 +1,7 @@
/**
* Events and data from sensors
*/
//% color=300 weight=99
//% color=#B4009E weight=99
namespace input {
/**
* Attaches code to run when the screen is facing up.

View File

@ -1,14 +1,14 @@
/**
* Control of the LED screen.
*/
//% color=3 weight=35
namespace led {
//% color=#5C2D91 weight=35
namespace led {
// what's the current high value
let barGraphHigh = 0;
// when was the current high value recorded
let barGraphHighLast = 0;
/**
* Displays a vertical bar graph based on the `value` and `high` value.
* If `high` is 0, the chart gets adjusted automatically.
@ -17,35 +17,35 @@ namespace led {
*/
//% help=/led/plot-bar-graph weight=20
//% blockId=device_plot_bar_graph block="plot bar graph of %value |up to %high" icon="\uf080" blockExternalInputs=true
export function plotBarGraph(value: number, high: number): void {
export function plotBarGraph(value: number, high: number): void {
let now = input.runningTime();
serial.writeString(value.toString() + "\r\n");
value = Math.abs(value);
if (high != 0) barGraphHigh = high;
else if (value > barGraphHigh || now - barGraphHighLast > 5000) {
barGraphHigh = value;
barGraphHighLast = now;
}
barGraphHigh = Math.max(barGraphHigh, 16);
let v = (value * 15) / barGraphHigh;
let k = 0;
for(let y = 4; y >= 0; --y) {
for (let y = 4; y >= 0; --y) {
for (let x = 0; x < 3; ++x) {
if (k > v) {
unplot(2-x,y);
unplot(2+x,y);
unplot(2 - x, y);
unplot(2 + x, y);
} else {
plot(2-x, y);
plot(2+x, y);
plot(2 - x, y);
plot(2 + x, y);
}
++k;
}
}
}
}
/**
* Toggles a particular pixel
* @param x TODO

View File

@ -77,17 +77,17 @@ enum BeatFraction {
/**
* Generation of music tones through pin ``P0``.
*/
//% color=52 weight=33
//% color=#D83B01 weight=98
namespace music {
var beatsPerMinute: number = 120;
let beatsPerMinute: number = 120;
/**
* Plays a tone through pin ``P0`` for the given duration.
* @param frequency TODO
* @param ms TODO
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone (Hz) %note=device_note|for (ms) %duration=device_beat" icon="\uf025" blockGap=8
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
export function playTone(frequency: number, ms: number): void {
pins.analogSetPitchPin(AnalogPin.P0);
pins.analogPitch(frequency, ms);
@ -95,7 +95,7 @@ namespace music {
/**
* Plays a tone through pin ``P0``.
* @param frequency TODO
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
@ -106,7 +106,7 @@ namespace music {
/**
* Rests (plays nothing) for a specified time through pin ``P0``.
* @param ms TODO
* @param ms rest duration in milliseconds (ms)
*/
//% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat"
@ -117,16 +117,16 @@ namespace music {
/**
* Gets the frequency of a note.
* @param name TODO
* @param name the note name
*/
//% weight=50 help=music/note-frequency
//% blockId=device_note block="%note"
export function noteFrequency(name: Note): number {
return name;
}
function init() {
if (beatsPerMinute <= 0) beatsPerMinute = 120;
if (beatsPerMinute <= 0) beatsPerMinute = 120;
}
/**

View File

@ -31,6 +31,11 @@ enum class AnalogPin {
P10 = MICROBIT_ID_IO_P10,
};
enum class PulseValue {
High = MICROBIT_PIN_EVT_PULSE_HI,
Low = MICROBIT_PIN_EVT_PULSE_LO
};
MicroBitPin *getPin(int id) {
switch (id) {
case MICROBIT_ID_IO_P0: return &uBit.io.P0;
@ -75,7 +80,6 @@ namespace pins {
return getPin(id);
}
/**
* Read the specified pin or connector as either 0 or 1
* @param name pin to read from
@ -124,11 +128,34 @@ namespace pins {
* @param name analog pin to set period to
* @param micros period in micro seconds. eg:20000
*/
//% help=pins/analog-set-period weight=23
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
void analogSetPeriod(AnalogPin name, int micros) {
PINOP(setAnalogPeriodUs(micros));
}
/**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
*/
//% help=pins/on-pulsed weight=22 blockGap=8
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return;
pin->eventOn(MICROBIT_PIN_EVENT_ON_PULSE);
registerWithDal((int)name, (int)pulse, body);
}
/**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/
//% help=pins/pulse-micros
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21
int pulseDuration() {
return pxt::lastEvent.timestamp;
}
/**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).

View File

@ -1,7 +1,7 @@
/**
* Control currents in Pins for analog/digital signals, servos, i2c, ...
*/
//% color=351 weight=30
//% color=#A80000 weight=30
namespace pins {
/**
* Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.
@ -11,7 +11,7 @@ namespace pins {
* @param toLow the lower bound of the value's target range
* @param toHigh the upper bound of the value's target range, eg: 4
*/
//% help=pins/map weight=15
//% help=pins/map weight=22
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;
@ -20,6 +20,8 @@ namespace pins {
/**
* Read one number from 7-bit I2C address.
*/
//% help=pins/i2c-read-number blockGap=8
//% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof" weight=7
export function i2cReadNumber(address: number, format: NumberFormat): number {
let buf = pins.i2cReadBuffer(address, pins.sizeOf(format))
return buf.getNumber(format, 0)
@ -28,6 +30,8 @@ namespace pins {
/**
* Write one number to a 7-bit I2C address.
*/
//% help=pins/i2c-write-number
//% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof" weight=6
export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void {
let buf = createBuffer(pins.sizeOf(format))
buf.setNumber(format, 0, value)
@ -37,6 +41,7 @@ namespace pins {
/**
* Get the size in bytes of specified number format.
*/
//%
export function sizeOf(format: NumberFormat) {
switch (format) {
case NumberFormat.Int8LE:

View File

@ -1,5 +1,24 @@
#include "ksbit.h"
enum class SerialPin {
P0 = MICROBIT_ID_IO_P0,
P1 = MICROBIT_ID_IO_P1,
P2 = MICROBIT_ID_IO_P2,
P8 = MICROBIT_ID_IO_P8,
P12 = MICROBIT_ID_IO_P12,
P13 = MICROBIT_ID_IO_P13,
P14 = MICROBIT_ID_IO_P14,
P15 = MICROBIT_ID_IO_P15,
P16 = MICROBIT_ID_IO_P16
};
enum class BaudRate {
//% block=115200
BaudRate115200 = 115200,
//% block=9600
BaudRate9600 = 9600
};
//% weight=2 color=30
namespace serial {
// note that at least one // followed by % is needed per declaration!
@ -7,16 +26,46 @@ namespace serial {
/**
* Reads a line of text from the serial port.
*/
//%
StringData* readString() {
return uBit.serial.readUntil(ManagedString("\r\n")).leakData();
//% help=serial/read-line
//% blockId=serial_read_line block="serial read line"
//% weight=20
StringData* readLine() {
return uBit.serial.readUntil(ManagedString("\n")).leakData();
}
/**
* Sends a piece of text through Serial connection.
*/
//% blockId=serial_writestring block="serial write %text"
//% help=serial/write-string
//% weight=87
//% blockId=serial_writestring block="serial write string %text"
void writeString(StringData *text) {
uBit.serial.send(ManagedString(text));
}
}
/**
* Registers an event to be fired when one of the delimiter is matched
* @param delimiters the characters to match received characters against. eg:"\n"
*/
// help=serial/on-data-received
// weight=19
void onDataReceived(StringData* delimiters, Action body) {
uBit.serial.eventOn(ManagedString(delimiters));
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
}
/**
* Dynamically configuring the serial instance to use pins other than USBTX and USBRX.
* @param tx the new transmission pins
* @param rx the new reception pin
* @param baud the new baud rate. eg: 115200
*/
//% weight=10
//% help=serial/redirect
//% blockId=serial_redirect block="serial redirect to|TX %tx|RX %rx|at baud rate %rate"
//% blockExternalInputs=1
void redirect(SerialPin tx, SerialPin rx, BaudRate rate) {
uBit.serial.redirect((PinName)tx, (PinName)rx);
uBit.serial.baud((int)rate);
}
}

View File

@ -1,22 +1,24 @@
/**
* Reading and writing data over a serial connection.
*/
//% weight=2 color=30
//% weight=2 color=#002050
namespace serial {
/**
* Prints a line of text to the serial
* @param value to send over serial
*/
//% help=serial/write-line
//% weight=90
//% help=serial/write-line blockGap=8
//% blockId=serial_writeline block="serial|write line %text"
export function writeLine(text: string): void {
writeString(text);
writeString("\r\n");
writeString(text + "\r\n");
}
/**
* Prints a numeric value to the serial
*/
//% help=serial/write-number
//% weight=89 blockGap=8
//% blockId=serial_writenumber block="serial|write number %value"
export function writeNumber(value: number): void {
writeString(value.toString());
@ -27,13 +29,20 @@ namespace serial {
* @param name name of the value stream, eg: x
* @param value to write
*/
//% weight=80
//% weight=88 blockGap=8
//% help=serial/write-value
//% blockId=serial_writevalue block="serial|write line %name|= %value"
//% blockId=serial_writevalue block="serial|write value %name|= %value"
export function writeValue(name: string, value: number): void {
writeString(name);
writeString(": ");
writeNumber(value);
writeLine("");
writeString(name + ":" + value + "\r\n");
}
/**
* Registers an event to be fired when a line has been received
*/
// help=serial/on-line-received
// blockId=serial_on_line_received block="serial on line received"
// weight=21 blockGap=8
export function onLineReceived(body: Action): void {
// serial.onDataReceived("\n", body);
}
}

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