Compare commits

...

98 Commits

Author SHA1 Message Date
24eb6f64db 0.3.37 2016-08-18 15:31:31 +03:00
0c99eaf7bf Bump pxt-core to 0.3.40 2016-08-18 15:31:31 +03:00
8eb3376cf5 Use embedded version of microbit to avoid yotta build 2016-08-18 14:26:56 +03:00
b863d5663d Add buffer shift rotate tests (moved from pxt) 2016-08-18 10:52:19 +03:00
aeb4cb6a17 0.3.36 2016-08-17 23:27:03 -07:00
fd88e0b7f0 Bump pxt-core to 0.3.39 2016-08-17 23:27:00 -07:00
ea0d2d4d02 add i2c fram to package list 2016-08-17 18:23:08 -07:00
adff537013 0.3.35 2016-08-17 17:06:44 -07:00
19fc284884 Bump pxt-core to 0.3.38 2016-08-17 17:06:42 -07:00
5d9f85828d updated blocks template 2016-08-17 17:05:10 -07:00
9f31637000 support for max-duration in pulse-in 2016-08-17 11:35:54 -07:00
8e811b913e adding pins.pulseIn API 2016-08-17 11:18:15 -07:00
269254796d add descriptions 2016-08-17 09:44:15 -07:00
46995cbd54 Adding max6675 package in built-in list 2016-08-17 09:44:08 -07:00
380488528f Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-08-17 08:40:45 -07:00
aca863f436 adding translation docs 2016-08-17 08:39:50 -07:00
a1ec25fd79 0.3.34 2016-08-17 18:09:20 +03:00
3e9d6d5895 Bump pxt-core to 0.3.37 2016-08-17 18:09:19 +03:00
719370f6b0 Use the new lambdas 2016-08-17 18:08:46 +03:00
2780497d4f 0.3.33 2016-08-17 17:15:09 +03:00
3eeaf2eddc Bump pxt-core to 0.3.36 2016-08-17 17:15:09 +03:00
eb3e91420c 0.3.32 2016-08-17 15:09:56 +03:00
38cd913020 Bump pxt-core to 0.3.35 2016-08-17 15:08:24 +03:00
9159c297a5 added wait-micros function 2016-08-16 17:04:21 -07:00
851687dba8 0.3.31 2016-08-16 13:44:38 -07:00
28b8006ec5 removing spurious logging 2016-08-16 10:11:55 -07:00
271128c075 answering questions about saving 2016-08-16 09:21:41 -07:00
a04ca0d715 0.3.30 2016-08-16 07:46:43 -07:00
8b89fe721d Bump pxt-core to 0.3.34 2016-08-16 07:46:39 -07:00
1baf04b1fd added links to packages 2016-08-15 23:16:10 -07:00
6c7f0f911c 0.3.29 2016-08-15 15:44:05 -07:00
f2008f9263 Bump pxt-core to 0.3.33 2016-08-15 15:44:03 -07:00
62127f7269 Updated VS code instructions 2016-08-15 11:03:03 -07:00
740cedd978 added docs 2016-08-12 16:15:41 -07:00
4278ff2b37 0.3.28 2016-08-12 08:36:34 -07:00
e7bea34d95 Bump pxt-core to 0.3.32 2016-08-12 08:36:33 -07:00
825409b697 0.3.27 2016-08-12 04:03:06 -07:00
8f72ac0094 Bump pxt-core to 0.3.31 2016-08-12 04:03:03 -07:00
8a6bb610e3 updated description 2016-08-12 03:37:27 -07:00
94dc141062 0.3.26 2016-08-11 16:33:03 -07:00
286dd1e50b Bump pxt-core to 0.3.29 2016-08-11 16:33:00 -07:00
6451d9add9 0.3.25 2016-08-11 16:24:34 -07:00
fd1dcde86b Bump pxt-core to 0.3.28 2016-08-11 16:24:30 -07:00
99947a9e21 0.3.24 2016-08-11 16:07:31 -07:00
a69239abed Bump pxt-core to 0.3.27 2016-08-11 16:07:29 -07:00
fd06fae050 0.3.23 2016-08-11 15:05:30 -07:00
7fbb056edf Bump pxt-core to 0.3.26 2016-08-11 15:05:29 -07:00
06758863fb 0.3.22 2016-08-11 14:38:08 -07:00
ad8af16a5a 0.3.21 2016-08-11 14:15:02 -07:00
70dd6bcac5 Bump pxt-core to 0.3.25 2016-08-11 14:14:59 -07:00
b103423a53 0.3.20 2016-08-11 12:11:04 -07:00
a82a44e587 Bump pxt-core to 0.3.23 2016-08-11 12:11:02 -07:00
e6f612283f remove dead page 2016-08-11 11:41:59 -07:00
fcd60876ab Removing streaming menu dialog 2016-08-11 11:41:07 -07:00
5daa9a0bb6 broken links 2016-08-11 10:44:17 -07:00
4fb3926073 fix snippets 2016-08-11 10:40:48 -07:00
73932f4619 0.3.19 2016-08-10 23:27:46 -07:00
c99138b02e adding SPI support 2016-08-10 23:26:58 -07:00
64d584681a docs tweaks 2016-08-10 16:09:57 -07:00
9788dd49cc fix testsnippet crash 2016-08-10 14:06:26 -07:00
9d15c4e270 fixing docs issues 2016-08-10 13:46:11 -07:00
fe7b06d763 0.3.18 2016-08-10 13:12:26 -07:00
0e0275e496 doc fixes 2016-08-10 13:10:40 -07:00
ffd4d96539 properly escape values in json payload 2016-08-10 09:28:22 -07:00
a6b4c9645a Merge pull request #199 from Microsoft/ignore-snippets
-ignore snippet notation
2016-08-10 08:29:05 -07:00
a9141d027f Add package info for server side check 2016-08-10 13:44:10 +01:00
807e581c3d Addition of ignore notation
Some snippets are designed to show syntax errors or refer to earlier variables. In this case the automated checker needs to avoid compiling them
2016-08-10 13:43:48 +01:00
41a4dfeb68 Documentation snippet fixes 2016-08-10 10:51:55 +01:00
4430391e87 0.3.17 2016-08-09 22:16:31 -07:00
81667f4df5 Bump pxt-core to 0.3.22 2016-08-09 22:16:28 -07:00
835048132c adjustments to electron app 2016-08-09 22:08:46 -07:00
00217305c2 0.3.16 2016-08-09 12:38:30 -07:00
85e8a70f76 Bump pxt-core to 0.3.21 2016-08-09 12:38:28 -07:00
bbdf27de5a adding pxt-neopixel to pre-populated package list 2016-08-09 11:02:23 -07:00
3e63d4083e update title 2016-08-09 10:27:39 -07:00
d1b8e3c752 added electron host 2016-08-09 09:55:37 -07:00
1164feb754 More snippet types 2016-08-09 16:55:43 +01:00
9ebd9d4f04 Add more snippet types for better detection 2016-08-09 16:52:24 +01:00
9fd2a3a3e6 Remove trailing whitespace 2016-08-09 16:39:50 +01:00
7f40889103 Add package info to mic docs (for testing) 2016-08-09 16:35:45 +01:00
ee37b4a959 Add package info to radio docs (for testing) 2016-08-09 16:28:08 +01:00
99d05ec91b Merge branch 'master' of https://github.com/thomasdenney/pxt-microbit 2016-08-09 16:11:27 +01:00
412e5bd034 Fix doc comment 2016-08-09 16:10:53 +01:00
141420d337 Correct Bluetooth doc comment 2016-08-09 16:05:25 +01:00
084f83ba1b Merge branch 'master' of https://github.com/thomasdenney/pxt-microbit 2016-08-09 15:13:35 +01:00
8601eff170 fixed snippets 2016-08-08 20:44:43 -07:00
5da4d74a2a adding messenger project 2016-08-08 18:12:34 -07:00
4215574a7c 0.3.15 2016-08-08 16:58:02 -07:00
da9d986a3e Bump pxt-core to 0.3.19 2016-08-08 16:58:00 -07:00
7481b9c24c call receiveNumber in onDataReceived to flush queue if needed (startup race)
fixed simulator issue when event onDataReceived gets raised
2016-08-08 16:54:43 -07:00
de5def8dde adding led.toggle as a block 2016-08-08 16:53:55 -07:00
dd011b977a wired up onPinReleased to simulator 2016-08-08 15:27:13 -07:00
20d0dd91ad added input.onPinRelease. Fix for #294 2016-08-08 15:23:18 -07:00
825c6d57e7 testing fr jsdoc transtions 2016-08-08 13:47:45 -07:00
b3edb81d3c adding URL for SEO 2016-08-08 13:08:15 -07:00
78089da134 0.3.14 2016-08-05 08:37:58 -07:00
3aef765d35 Bump pxt-core to 0.3.18 2016-08-05 08:37:56 -07:00
e942fb5733 Minor linting changes 2016-07-18 10:12:00 +01:00
120 changed files with 1508 additions and 709 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@ clients/win10/app/bld
clients/win10/*.opendb
clients/**/bin/**
clients/**/obj/**
clients/electron/projects
*.user
*.sw?

67
clients/electron/main.js Normal file
View File

@ -0,0 +1,67 @@
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// pxt toolchain
const pxt = require('pxt-core')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow() {
console.log('starting app...')
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800, height: 600,
webPreferences: {
nodeIntegration: false,
}
})
ts.pxt.Util.debug = true;
pxt.mainCli("C:/gh/pxt-microbit/clients/electron/node_modules/pxt-microbit", ["serve", "-just"]);
// no menu
mainWindow.setMenu(null);
// and load the index.html of the app.
mainWindow.loadURL(`http://localhost:3232/#local_token=08ba9b8f-6ccb-4202-296d-28fac7a553d9`)
// Open the DevTools.
mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

View File

@ -0,0 +1,19 @@
{
"name": "codethemicrobit",
"version": "0.1.0",
"description": "A Blocks / JavaScript editor for the micro:bit",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "Microsoft",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "^1.2.0"
},
"dependencies": {
"typescript": "1.8.7",
"pxt-core": "*",
"pxt-microbit": "*"
}
}

View File

@ -23,6 +23,8 @@ input.onButtonPressed(Button.B, () => {
```
# About
### @description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
The [BBC micro:bit](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).

View File

@ -1,8 +1,14 @@
# Blocks language
### @description Langugage constructs for the Block editor.
```namespaces
for (let i = 0;i<5;++i) {}
if (true){}
let x = 0;
Math.random(5);
```
```
## See Also
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables)

View File

@ -46,7 +46,7 @@ basic.showNumber(counter);
To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10:
```blocks
```blocks
let counter = 1;
counter = counter + 10;
basic.showNumber(counter);

54
docs/code.md Normal file
View File

@ -0,0 +1,54 @@
# Visual Studio Code
Visual Studio Code is a Free Open Source code editor that you can use to edit your programs.
Working from Visual Studio code allows you to benefit from all the features
of a professional IDE while working with PXT: working with files,
git integration (or source control of your choice), hundreds of extensions.
![](https://code.visualstudio.com/home/home-screenshot-win-lg.png)
## Setup
Follow these instructions to setup your machine and edit your programs in Visual Studio Code.
* install [Visual Studio Code](https://code.visualstudio.com/)
* install [Node.JS](https://nodejs.org/en/)
* install the PXT Tools (on Mac or Linux, you might have to add ``sudo`` to the command).
```
pxt install -g pxt
```
* create a folder for your projects
```
mkdir microbit
```
* install the microbit target
```
pxt target microbit
```
That's it! You are ready to create new projects in code or open existing projects.
## Creating a new project
Open a shell to your ``microbit`` folder.
```
# create a new subfolder for your project
mkdir myproject
cd myproject
# start the project set
pxt init
# open code
code .
```
## Opening an existing project
You can extract a project from the embedded URL or .hex file. Open a shell to your projects folder
```
# extract the project from the URL
pxt extract EMBEDURL
```
where ``EMBEDURL`` is the published project URL.

View File

@ -48,41 +48,45 @@ The micro:bits *scheduler* provides the capability to concurrently execute di
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses.
```
export function countButtonPresses() {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
}
```
The program above contains three statements that execute in order from top to bottom. The first statement
```
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
count++;
})
```
informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one. The second statement
```
basic.forever(() => {
basic.showNumber(count, 150)
})
```
queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
The program above contains three statements that execute in order from top to bottom.
The first statement initializes the global variable `count` to zero.
```
count = 0
```blocks
let count = 0
```
initializes the global variable `count` to zero. The function ends after the execution of these three statements, but this is not the end of program execution! Thats because the function queued the `forever` loop for execution by the scheduler.
The second statement informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one.
```blocks
let count = 0
// ...
input.onButtonPressed(Button.A, () => {
count++;
})
```
The third statement queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
```blocks
let count = 0
// ...
basic.forever(() => {
basic.showNumber(count, 150)
})
```
The function ends after the execution of these three statements, but this is not the end of program execution! Thats because the function queued the `forever` loop for execution by the scheduler.
The second job of the scheduler is to periodically interrupt execution to read (poll) the various inputs to the micro:bit (the buttons, pins, etc.) and fire off events (such as “button A pressed”). Recall that the firing of an event causes the event handler subprogram associated with that event to be queued for later execution. The scheduler uses a timer built into the micro:bit hardware to interrupt execution every 6 milliseconds and poll the inputs, which is more than fast enough to catch the quickest press of a button.
@ -96,9 +100,18 @@ If you hadnt guessed already, a footballer represents subprogram and dribblin
We will call this “passing control of execution” rather than “passing the ball”. However, in the world of the micro:bit, the concurrently executing subprograms are not aware of each other, so they dont actually pass control directly to one another. Rather they pass control of execution back to the scheduler and the scheduler determines the subprogram to pass control to next. The programmer inserts a call to the `pause` function to indicate a point in the subprogram where control of execution passes to the scheduler. Also, when a subprogram ends execution, control passes to the scheduler.
Lets take a look at the implementation of the `forever` statement to see an example of cooperative scheduling:
Lets take a look at the implementation of the `basic.forever` function to see an example of cooperative scheduling:
![](/static/mb/device/reactive-2.png)
```typescript
function forever(body: () => void) {
control.inBackground(() => {
while(true) {
body()
basic.pause(20)
}
})
}
```
The `forever` loop actually is a function that takes a subprogram (an *Action* in Touch Develop) as a parameter. The function uses the `control -> in background` function of the micro:bit runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds).
@ -128,15 +141,15 @@ Through this example, we have seen that the micro:bit scheduler enables you to c
As a result, you can easily add a new capability to the micro:bit by just adding a new subprogram. For example, if you want to add a reset feature to the counter program, all you need to do is add a new event handler for a press of button B that sets the global variable "count" to zero, as shown below:
```
```typescript
export function countButtonPressesWithReset() {
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
input.onButtonPressed(Button.B, () => {
count = 0
})

View File

@ -1,5 +1,7 @@
# Documentation
### @description Links to the documentation, reference and projects.
### Things to do
* **[Getting Started](/getting-started)**
@ -19,6 +21,7 @@
### More questions?
* [Frequently Asked Question](/faq)
* [Help Translate](/translate)
* [Release notes](/release-notes)
### Developers

View File

@ -1,9 +1,30 @@
# Frequently Asked Questions
### @description Frequently asked questions and answers from our users.
### Where can I get a BBC micro:bit?
More information at [http://uk.farnell.com/bbc-microbit](http://uk.farnell.com/bbc-microbit).
### How do I send feedback?
Find the small bubble icon on the bottom of the editor and
post your feedback from there!
### How do I save my code?
The web editor automatically saves your code in the browser cache. Simply reopen the browser and navigate to the web editor
to reopen your latest project. You can also open previous project stored locally through **More -> Open Project**.
The project source is also stored in each compiled ``.hex`` file. Drag and drop the ``.hex`` file into the web editor to load the project.
To share your project with others, you can use the **Embed** feature. It stores your project in the cloud and creates a URL that you can share with others.
If you are using [Visual Studio Code](/code), all your programs are stored as files on your computer and you can use your favorite source control system as needed.
## Is the web site available in other languages?
You can [help us translate](/translate) the web site, documentation and blocks via our crowd-source translations!
## Troubleshooting

View File

@ -1,5 +1,7 @@
# Getting started
### @description An activity for beginners to get started with the micro:bit
## ~avatar
Here are some challenges for you. Arrange the blocks in the editor

View File

@ -1,4 +1,4 @@
# JavaScript and TypeScript
# JavaScript
Visit the cards below to starting programming JavaScript and TypeScript with the micro:bit:
@ -34,3 +34,8 @@ Visit the cards below to starting programming JavaScript and TypeScript with the
]
```
### See Also
[calling](/js/call), [sequencing](/js/sequence), [variables](/js/variables), [operators](/js/operators), [statements](/js/statements), [functions](/js/functions),
[types](/js/types), [classes](/js/classes), [FAQ](/js/faq)

View File

@ -49,7 +49,7 @@ basic.clearScreen()
It's a syntax error to have a left parenthesis without the "closing" right parenthesis:
```typescript
```
basic.clearScreen(
```

View File

@ -43,7 +43,7 @@ Of course, one of the most fundamental patterns in class-based programming is be
Let's take a look at an example:
```ts
```ts-ignore
class Animal {
name: string;
constructor(theName: string) { this.name = theName; }
@ -105,7 +105,7 @@ In TypeScript, each member is `public` by default.
You may still mark a member `public` explicitly.
We could have written the `Animal` class from the previous section in the following way:
```ts
```ts-ignore
class Animal {
public name: string;
public constructor(theName: string) { this.name = theName; }
@ -119,7 +119,7 @@ class Animal {
When a member is marked `private`, it cannot be accessed from outside of its containing class. For example:
```ts
```ts-ignore
class Animal {
private name: string;
constructor(theName: string) { this.name = theName; }
@ -138,7 +138,7 @@ The same applies to `protected` members.
Let's look at an example to better see how this plays out in practice:
```ts
```ts-ignore
class Animal {
private name: string;
constructor(theName: string) { this.name = theName; }
@ -174,7 +174,7 @@ Even though `Employee` also has a `private` member called `name`, it's not the o
The `protected` modifier acts much like the `private` modifier with the exception that members
declared `protected` can also be accessed by instances of deriving classes. For example,
```ts
```ts-ignore
class Person {
protected name: string;
constructor(name: string) { this.name = name; }
@ -204,7 +204,7 @@ we can still use it from within an instance method of `Employee` because `Employ
A constructor may also be marked `protected`.
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,
```ts
```ts-ignore
class Person {
protected name: string;
protected constructor(theName: string) { this.name = theName; }
@ -233,7 +233,7 @@ let john = new Person("John"); // Error: The 'Person' constructor is protected
You can make properties readonly by using the `readonly` keyword.
Readonly properties must be initialized at their declaration or in the constructor.
```ts
```ts-ignore
class Octopus {
readonly name: string;
readonly numberOfLegs: number = 8;
@ -252,7 +252,7 @@ This turns out to be a very common practice.
*Parameter properties* let you create and initialize a member in one place.
Here's a further revision of the previous `Octopus` class using a parameter property:
```ts
```ts-ignore
class Octopus {
readonly numberOfLegs: number = 8;
constructor(readonly name: string) {

View File

@ -45,7 +45,7 @@ TypeScript can figure the return type out by looking at the return statements, s
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
```ts
```ts-ignore
function buildName(firstName: string, lastName: string) {
return firstName + " " + lastName;
}
@ -60,7 +60,7 @@ When they do, their value is `undefined`.
We can get this functionality in TypeScript by adding a `?` to the end of parameters we want to be optional.
For example, let's say we want the last name parameter from above to be optional:
```ts
```ts-ignore
function buildName(firstName: string, lastName?: string) {
if (lastName)
return firstName + " " + lastName;
@ -80,7 +80,7 @@ In TypeScript, we can also set a value that a parameter will be assigned if the
These are called default-initialized parameters.
Let's take the previous example and default the last name to `"Smith"`.
```ts
```ts-ignore
function buildName(firstName: string, lastName = "Smith") {
return firstName + " " + lastName;
}
@ -115,7 +115,7 @@ Unlike plain optional parameters, default-initialized parameters don't *need* to
If a default-initialized parameter comes before a required parameter, users need to explicitly pass `undefined` to get the default initialized value.
For example, we could write our last example with only a default initializer on `firstName`:
```ts
```ts-ignore
function buildName(firstName = "Will", lastName: string) {
return firstName + " " + lastName;
}
@ -134,7 +134,7 @@ In JavaScript, you can work with the arguments directly using the `arguments` va
In TypeScript, you can gather these arguments together into a variable:
```ts
```ts-ignore
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}
@ -148,7 +148,7 @@ The compiler will build an array of the arguments passed in with the name given
The ellipsis is also used in the type of the function with rest parameters:
```ts
```ts-ignore
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}

View File

@ -44,7 +44,7 @@ Another property of block-scoped variables is that they can't be read or written
While these variables are "present" throughout their scope, all points up until their declaration are part of their *temporal dead zone*.
This is just a sophisticated way of saying you can't access them before the `let` statement, and luckily TypeScript will let you know that.
```typescript
```typescript-ignore
a++; // illegal to use 'a' before it's declared;
let a;
```

View File

@ -1,5 +1,7 @@
# Lessons
### @description Lessons to teach computer science and coding.
### @short Lessons
### ~column

View File

@ -62,7 +62,7 @@ export function newAction() {
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
```
```blocks
// **. . .**
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150) // ***

View File

@ -86,3 +86,7 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
```package
microbit-radio
```

View File

@ -34,8 +34,7 @@ Let's code the third part of Happy Birthday!
To do this, you need to add blocks after the last line of the `play` blocks. We want to continue to adding musical chords with the `play` block. Then insert the appropriate chord blocks `G`, `E`, `C`, `B`, `A` to complete the third part of the song. Modify your code so that your code looks like this.
``` blocks
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
@ -57,8 +56,7 @@ music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
basic.pause(100);
```
```
* click *run * to see if the code works as expected.

View File

@ -73,6 +73,7 @@ coll.push("cow")
<br/>
```blocks
let coll: string[] = []
let index = Math.random(coll.length)
let word = coll[index]
```

View File

@ -39,7 +39,7 @@ coll.push("cat")
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
```
```ts
let coll = (<string[]>[])
```

View File

@ -42,3 +42,7 @@ radio.onDataReceived(() => { })
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to run code when an input button is pressed
* learn how to pause your code for the specified number of milliseconds
```package
microbit-radio
```

View File

@ -162,3 +162,7 @@ radio.onDataReceived(() => {
Connect the first micro:bit to your computer using your USB cable and run the pogo script on it.
Connect the second micro:bit to your computer using your USB cable and run the pogo script on it.
The first person and second person take turns jumping in the “y” direction while the other player uses the micro:bit to track the results on the micro:bit!
```package
microbit-radio
```

View File

@ -33,3 +33,7 @@ radio.receiveNumber();
* learn how to return the sum of the two numbers
* learn how to get acceleration value in milli-gravitys
* learn how to read the connector value as analog as a value comprised between 0 and 1023
```package
microbit-radio
```

View File

@ -195,4 +195,6 @@ Let's select Style 10 as an example.
* The first person and second person take shaking or moving the micor:bit in any direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel
```package
microbit-radio
```

View File

@ -2,8 +2,18 @@
The editor is open source on GitHub under the MIT license. Contributions are welcome, please check our GitHub repos.
### Repos
## Source Code
* [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-core](https://github.com/Microsoft/pxt-microbit-core), Yotta module used to build the BBC micro:bit runtime
## C++ Runtime
The [C++ 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).
## Packages
* [microsoft/pxt-neopixel](https://github.com/microsoft/pxt-neopixel), package for neopixel strips
* [microsoft/pxt-max6675](https://github.com/microsoft/pxt-max6675), package for Temperature Probe (MAX6675)

View File

@ -1,14 +1,19 @@
# Extensions
# Packages
You can publish libraries (also known as packages or extensions)
that users can then add to their scripts. These typically
provide a driver for a particular hardware device you can connect
to a microbit.
* [pxt-max6675](https://github.com/Microsoft/pxt-max6675) -- TypeScript
* [pxt-neopixel](https://github.com/Microsoft/pxt-neopixel) -- TypeScript + ARM Thumb assembly package
* [pxt-sonar](https://github.com/microsoft/pxt-sonar) -- TypeScript
* [pxt-i2c-fram](https://github.com/microsoft/pxt-i2c-fram) -- TypeScript
* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample)
* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram)
## Finding libraries
## Finding packages
From the editor, the user clicks on **More** then **Add Package** and searches for the package.
@ -16,11 +21,11 @@ To see the list of packages, click on **More** then **Show Files** to see the pr
To remove a package, click on the garbage button in the file list next to the package.
## Publishing libraries
## Publishing packages
Packages can be published from the pxt command line. We are still sorting out the details.
## Localizing libraries
## Localizing packages
It is possible to package localization strings for the **jsDoc** description associated to the API in the package.

View File

@ -47,5 +47,6 @@ Here are some cool projects that you can build with your micro:bit!
}]
```
### See Also
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Watch](/projects/the-watch)

View File

@ -0,0 +1,65 @@
# messenger
![](/static/mb/projects/a9-radio.png)
Use the radio to create an app that sends "YO" messages.
## Step 1
Use [on button pressed](/reference/input/on-button-pressed) to send the number "0" over radio.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(0);
});
```
## Step 2
Use [radio on data received](/reference/radio/on-data-received) display "YO" when the number ``0`` is received
by radio.
```blocks
let message = 0;
radio.onDataReceived(() => {
message = radio.receiveNumber();
if (message == 0) {
basic.showString("YO")
}
})
```
Compile the program and **upload the same .hex file to 2 devices!**
## Step 3
Use [on button pressed](/reference/input/on-button-pressed) to send the number "1" over radio.
```blocks
input.onButtonPressed(Button.B, () => {
radio.sendNumber(1);
});
```
## Step 4
Add blocks in [radio on data received](/reference/radio/on-data-received) to display "BYE" when the number ``1`` is received
by radio.
```blocks
let message = 0;
radio.onDataReceived(() => {
message = radio.receiveNumber();
if (message == 0) {
basic.showString("YO")
}
if (message == 1) {
basic.showString("BYE")
}
})
```
```package
microbit-radio
```

View File

@ -89,4 +89,8 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
### ~button /projects/the-watch
NEXT: The Watch
### ~
### ~
```package
microbit-radio
```

View File

@ -1,12 +1,12 @@
# telegraph activity
Build a telgraph.
Build a telegraph.
# micro:bit telegraph
Have you ever tried to communicate through a telegraph? Let's try coding a "Telegraph" on two BBC micro:bits !
Complete the following [guided tutorial](/projects/telegraph), your hack should look like this:
Complete the following [tutorial](/projects/telegraph), your hack should look like this:
![](/static/mb/lessons/telegraph-0.png)

View File

@ -1,5 +1,7 @@
# Reference
### @description List of API categories available in the editors
```namespaces
basic.showNumber(0);
input.onButtonPressed(Button.A, () => {
@ -30,6 +32,11 @@ bluetooth.onBluetoothConnected(() => {});
```
```package
microbit-radio
microbit-devices
microbit-bluetooth
```
```
### See Also
[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth)

View File

@ -3,3 +3,7 @@
```cards
String.fromCharCode(0);
```
### See Also
[fromCharCode](/reference//math/string-from-char-code)

View File

@ -32,3 +32,7 @@ basic.showAnimation(`
. . . . .
`);
```
### See Also
[showNumber](/reference/basic/show-number), [showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string), [clearScreen](/reference/basic/clear-screen), [forever](/reference/basic/forever), [pause](/reference/basic/pause), [plotLeds](/reference/basic/plot-leds), [showAnimation](/reference/basic/show-animation)

View File

@ -23,7 +23,7 @@ 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.
```
```blocks
basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
@ -47,7 +47,7 @@ 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.
```
```blocks
basic.showAnimation(`
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .

View File

@ -22,3 +22,7 @@ bluetooth.onBluetoothDisconnected(() => {
```package
microbit-bluetooth
```
### See Also
[startAccelerometerService](/reference/bluetooth/start-accelerometer-service), [startButtonService](/reference/bluetooth/start-button-service), [startIOPinService](/reference/bluetooth/start-io-pin-service), [startLEDService](/reference/bluetooth/start-led-service), [startMagnetometerService](/reference/bluetooth/start-magnetometer-service), [startTemperatureService](/reference/bluetooth/start-temperature-service), [uartRead](/reference/bluetooth/uart-read), [uartWrite](/reference/bluetooth/uart-write), [onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected)

View File

@ -7,4 +7,9 @@ control.inBackground(() => {
});
control.reset();
control.waitMicros(4);
```
### See Also
[inBackground](/reference/control/in-background), [reset](/reference/control/reset), [wait-micros](/reference/control/wait-micros)

View File

@ -0,0 +1,32 @@
# WaitMicros
Blocks the current fiber for the given amount of micro-seconds.
```sig
control.waitMicros(4)
```
### Example
This program sends a 10 micro-second HIGH pulse through pin ``P0``.
```blocks
// ensure pin is low to send a clean pulse
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
// set pin to 1 and wait 10 micros
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
// finish pulse
pins.digitalWritePin(DigitalPin.P0, 0)
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See Also
[pause](/reference/basic/pause)

View File

@ -17,3 +17,11 @@ devices.onSignalStrengthChanged(() => {
});
```
```package
microbit-devices
```
### See Also
[tellCameraTo](/reference/devices/tell-camera-to), [tellRemoteControlTo](/reference/devices/tell-remote-control-to), [raiseAlertTo](/reference/devices/raise-alert-to), [onNotified](/reference/devices/on-notified), [onGamepadButton](/reference/devices/on-gamepad-button), [signalStrength](/reference/devices/signal-strength), [onSignalStrengthChanged](/reference/devices/on-signal-strength-changed)

View File

@ -0,0 +1,38 @@
# On Signal Strength Changed
Register code to run when the signal strength of the paired device changes.
### ~hint
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device,
such as a smartphone, over Bluetooth (Smart).
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### ~
```sig
devices.onNotified(MesDeviceInfo.IncomingCall, () => {})
```
### Parameters
* ``body``: code to run when the signal strength changes.
### Examples
Display the signal strength on screen:
```blocks
devices.onNotified(MesDeviceInfo.IncomingCall, () => {
basic.showString("RING RING")
})
```
### See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength)
```package
microbit-devices
```

View File

@ -23,7 +23,7 @@ devices.onSignalStrengthChanged(() => {})
Display the signal strength on screen:
```
```blocks
devices.onSignalStrengthChanged(() => {
basic.showNumber(devices.signalStrength(), 150)
})

View File

@ -1,47 +0,0 @@
# tell microphone to
The tell microphone to function.
Access the audio recording capabilities of the device using the ``tell microphone to`` function.
The functions in the antenna namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### Block Editor
![](/static/mb/tell-microphone-to-0.png)
### JavaScript
```
export function tellMicrophoneTo(event: string)
```
### Parameters
* event - an event identifier
### Event values
* play
* stop
* pause
* forward
* rewind
* volume up
* volume down
* previous track
* next track
### Examples
To tell the connected device to start recording audio
```
devices.tellMicrophoneTo("start capture")
```
To tell the connected device to stop recording audio
```
devices.tellMicrophoneTo("stop capture")
```

View File

@ -9,3 +9,7 @@ game.startCountdown(10000);
game.gameOver();
game.setScore(0);
```
### See Also
[addScore](/reference/game/change-score-by), [score](/reference/game/score), [startCountdown](/reference/game/start-countdown), [gameOver](/reference/game/game-over), [setScore](/reference/game/set-score)

View File

@ -6,7 +6,7 @@ Turn off all the pixels in an [Image](/reference/images/image).
### JavaScript
```
```sig
export function clear(img: micro_bit.Image)
```
@ -18,7 +18,7 @@ export function clear(img: micro_bit.Image)
The following example turns off the pixels of `img` when the A input button is pressed:
```
```blocks
let img = images.createImage(`
. . . . .
. # # # .

View File

@ -2,12 +2,12 @@
Reports the x position of a sprite on the LED screen
```
```sig
export function x(_this: micro_bitSprites.LedSprite) : number
```
Reports the y position of a sprite on the LED screen
```
```sig
export function y(_this: micro_bitSprites.LedSprite) : number
```

View File

@ -4,24 +4,24 @@ Reports the x or y position, the current direction of a sprite, or the brightne
Reports the x position of a sprite on the LED screen
```
```sig
export function x(_this: micro_bitSprites.LedSprite) : number
```
Reports the y position of a sprite on the LED screen
```
```sig
export function y(_this: micro_bitSprites.LedSprite) : number
```
Reports the brightness of a sprite on the LED screen
```
```sig
export function brightness(_this: micro_bitSprites.LedSprite) : number
```
Reports the current direction of a sprite on the LED screen
```
```sig
export function direction(_this: micro_bitSprites.LedSprite) : number
```

View File

@ -0,0 +1,30 @@
# Set Score
Sets the current score.
```sig
game.setScore(1)
```
### Parameters
* a [number](/reference/types/number) that represents the new score.
### Examples
This program is a simple game.
Press button ``A`` as much as possible to increase the score.
Press ``B`` to display the score and reset the score.
```blocks
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score())
game.setScore(0)
})
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```
### See Also
[score](/reference/game/score), [start countdown](/reference/game/start-countdown)

View File

@ -18,3 +18,7 @@ images.createBigImage(`
. . . . .
`);
```
### See Also
[createImage](/reference/images/create-image), [createBigImage](/reference/images/create-big-image)

View File

@ -6,7 +6,7 @@ Get the state of a pixel in an [Image](/reference/images/image).
### JavaScript
```
```sig
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean
```
@ -29,7 +29,7 @@ This example gets the state of pixel `0, 0` in the `img` variable:
### ~hide
```
```blocks
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
@ -41,7 +41,7 @@ let img = images.createImage(`
### ~
```
```typescript-ignore
let state = img.pixel(0, 0)
```

View File

@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
### JavaScript
```
```sig
export function plotFrame(_this: micro_bit.Image, index: number)
```
@ -20,7 +20,7 @@ The `plot frame` function takes the index of the frame (if there are two frames,
### Example
```
```blocks
let img = images.createImage(`
# . . . # # . . . #
. # . # . . # # # .

View File

@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
### JavaScript
```
```sig
export function plotImage(_this: micro_bit.Image, xOffset: number)
```
@ -20,7 +20,7 @@ The `show image` function has a built in delay of 400ms after display of the ima
### Example
```
```blocks
let img = images.createImage(`
# . . . # # . . . #
. # . # . . # # # .

View File

@ -6,7 +6,7 @@ Set the on/off state of pixel in an [Image](/reference/images/image).
### JavaScript
```
```sig
export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean)
```
@ -24,7 +24,7 @@ To figure out the ``x``, ``y`` coordinates, see [LED screen](/device/screen).
The following example creates an image and stores it in the `img` variable. The `set pixel` function sets the centre pixel off, before `img` is shown using `show image`.
```
```blocks
let img = images.createImage(`
. . # . .
. # . # .

View File

@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
### JavaScript
```
```sig
export function showFrame(img: micro_bit.Image, frame: number)
```
@ -20,7 +20,7 @@ The `show frame` function is the same as [plot frame](/reference/images/plot-fra
### Example
```
```blocks
let img = images.createImage(`
# . . . # # . . . #
. # . # . . # # # .

View File

@ -20,7 +20,7 @@ The following example gets the width of `img` and stores it in the `w` variable:
### ~hide
```
```blocks
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
@ -32,7 +32,7 @@ let img = images.createImage(`
### ~
```
```typescript-ignore
let w = img.width()
```
@ -40,7 +40,7 @@ let w = img.width()
The following example uses the `width` function with a [for](/blocks/loops/for) loop to show each image frame on the screen:
```
```typescript
let img2 = images.createImage(`
. . # . . . # # # # . # # # .
. # # . . . . . . # . . . # .

View File

@ -39,3 +39,7 @@ input.onShake(() => {
});
```
### See Also
[onButtonPressed](/reference/input/on-button-pressed), [onGesture](/reference/input/on-gesture), [onPinPressed](/reference/input/on-pin-pressed), [buttonIsPressed](/reference/input/button-is-pressed), [compassHeading](/reference/input/compass-heading), [pinIsPressed](/reference/input/pin-is-pressed), [temperature](/reference/input/temperature), [acceleration](/reference/input/acceleration), [lightLevel](/reference/input/light-level), [rotation](/reference/input/rotation), [magneticForce](/reference/input/magnetic-force), [runningTime](/reference/input/running-time), [setAccelerometerRange](/reference/input/set-accelerometer-range), [calibrate](/reference/input/calibrate), [onLogoDown](/reference/input/on-logo-down), [onLogoUp](/reference/input/on-logo-up), [onScreenDown](/reference/input/on-screen-down), [onScreenUp](/reference/input/on-screen-up), [onShake](/reference/input/on-shake)

View File

@ -0,0 +1,48 @@
# On Pin Released
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 release pin `0`, `1`, or `2`
together with `GND`. When you are using this function in a web
browser, click and release the pins on the screen instead of the ones on the BBC
micro:bit.
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.onPinReleased(TouchPin.P0, () => {
})
```
## ~hint
This function works best when the BBC micro:bit is using batteries for power,
instead of the USB cable.
## ~
## Parameters
* ``name`` means the pin that is being released, either `P0`, `P1`, or `P2`
### Example: pin pressed counter
This program counts how many times you release the `P0` pin.
Every time you release the pin, the program shows the number of times on the screen.
```blocks
let count = 0
basic.showNumber(count, 100)
input.onPinReleased(TouchPin.P0, () => {
count = count + 1
basic.showNumber(count, 100)
})
```
### 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

@ -18,3 +18,7 @@ led.toggle(0, 0);
led.toggleAll();
led.setDisplayMode(DisplayMode.BackAndWhite);
```
### See Also
[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode)

View File

@ -12,3 +12,7 @@ music.tempo();
music.changeTempoBy(20);
music.setTempo(120);
```
### See Also
[playTone](/reference/music/play-tone), [ringTone](/reference/music/ring-tone), [rest](/reference/music/rest), [noteFrequency](/reference/music/note-frequency), [beat](/reference/music/beat), [tempo](/reference/music/tempo), [changeTempoBy](/reference/music/change-tempo), [setTempo](/reference/music/set-tempo)

View File

@ -13,11 +13,17 @@ pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
});
pins.pulseDuration();
pins.pulseIn(DigitalPin.P0, PulseValue.High);
pins.servoWritePin(AnalogPin.P0, 180);
pins.servoSetPulse(AnalogPin.P0, 1500);
pins.i2cReadNumber(0, NumberFormat.Int8LE);
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
pins.spiWrite(0);
pins.setPull(DigitalPin.P0, PinPullMode.PullDown);
pins.analogPitch(0, 0);
pins.analogSetPitchPin(AnalogPin.P0);
```
### See Also
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [pulseIn](/reference/pins/pulse-in), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch), [spiWrite](/reference/pins/spi-write)

View File

@ -13,7 +13,7 @@ pins.analogPitch(440, 300)
### Example
```
```blocks
pins.analogSetPitchPin("P0")
let frequency1 = 440
let duration = 1000

View File

@ -12,7 +12,7 @@ pins.analogSetPitchPin(AnalogPin.P0)
### Example
```
```blocks
pins.analogSetPitchPin(AnalogPin.P0)
let frequency = 440
let duration = 1000

View File

@ -27,6 +27,12 @@ format from the 7-bit I2C address `32`.
pins.i2cReadNumber(32, NumberFormat.UInt16BE);
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)

View File

@ -27,6 +27,13 @@ address `32` in big-endian 32-bit integer format.
```blocks
pins.i2cWriteNumber(32, 2055, NumberFormat.Int32BE);
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)

View File

@ -0,0 +1,54 @@
# Pulse In
Returns the duration of a pulse (high or low) from a [pin](/device/pins) on
the micro:bit board in microseconds.
```sig
pins.pulseIn(DigitalPin.P0, PulseValue.High)
```
### ~avatar
Some pins are also used by the [LED screen](/device/screen).
Please read the [page about pins](/device/pins) carefully.
### ~
### Parameters
* ``name`` is a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``)
* ``value`` is the value of the pulse, ``high`` or ``low``
* ``maxDuration``, maximum duration in micro-seconds. If no pulse is received
### Returns
* a [number](/reference/types/number) that represents the pulse duration in micro-seconds
### Example: Measuring distance with a sonar
The following script sends a pulse on ``P0`` and reads the pulse returned by a HC-SR04 sonar to determine the distance of the object in front of the sensor.
```blocks
basic.forever(() => {
// send pulse
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
pins.digitalWritePin(DigitalPin.P0, 0)
// read pulse
led.plotBarGraph(pins.pulseIn(DigitalPin.P1, PulseValue.High) / 58, 0)
basic.pause(100)
})
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[digital write pin](/reference/pins/digital-write-pin),

View File

@ -29,7 +29,7 @@ pins.servoWritePin(AnalogPin.P0, 90)
```blocks
basic.forever(() => {
let millig = input.acceleration(Dimensions.X)
let millig = input.acceleration(Dimension.X)
// map accelerometer readings to angle
let angle = pins.map(millig, -1023, 1023, 0, 180)
pins.servoWritePin(AnalogPin.P0, angle)

View File

@ -0,0 +1,19 @@
# SPI Write
Write to the SPI Slave and return the response.
```sig
pins.spiWrite(0);
```
### Parameters
* ``value``: value Data to be sent to the SPI slave
### Returns
* a [number](/reference/types/number) Response from the SPI slave
### See also
[SPI](https://developer.mbed.org/handbook/SPI)

View File

@ -15,6 +15,14 @@ radio.receiveString();
radio.receivedSignalStrength();
radio.setGroup(0);
radio.setTransmitPower(7);
radio.writeValueToSerial();
radio.setTransmitSerialNumber(false);
radio.writeValueToSerial();
```
```package
microbit-radio
```
### See Also
[sendNumber](/reference/radio/send-number), [sendValue](/reference/radio/send-value), [sendString](/reference/radio/send-string), [onDataReceived](/reference/radio/on-data-received), [receiveNumber](/reference/radio/receive-number), [receivedNumberAt](/reference/radio/received-number-at), [receiveString](/reference/radio/receive-string), [receivedSignalStrength](/reference/radio/received-signal-strength), [setGroup](/reference/radio/set-group), [setTransmitPower](/reference/radio/set-transmit-power), [setTransmitSerialNumber](/reference/radio/set-transmit-serial-number), [writeValueToSerial](/reference/radio/write-value-to-serial)

View File

@ -33,3 +33,6 @@ radio.onDataReceived(() => {
[receive number](/reference/radio/receive-number),
[send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
```package
microbit-radio
```

View File

@ -64,3 +64,6 @@ basic.forever(() => {
[send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -89,3 +89,7 @@ radio.onDataReceived(() => {
### See also
[send string](/reference/radio/send-string), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -38,3 +38,7 @@ basic.forever(() => {
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -43,3 +43,7 @@ basic.forever(() => {
### See also
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -40,3 +40,7 @@ A radio that can both transmit and receive is called a _transceiver_.
### See also
[receive string](/reference/radio/receive-string), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -44,3 +44,6 @@ radio.onDataReceived(() => {
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -34,3 +34,6 @@ radio.setGroup(128)
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -38,3 +38,7 @@ 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)
```package
microbit-radio
```

View File

@ -0,0 +1,31 @@
# Set Transmit Serial Number
Make the ``radio`` packet embed the board serial number with each packet of data.
```sig
radio.setTransmitSerialNumber(true);
```
### Parameters
* ``transmit`` is a [boolean](/reference/types/boolean) that represents whether the serial number needs to be transmitted.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program makes the ``radio`` send the serial number in each packet.
```blocks
radio.setTransmitSerialNumber(true);
```
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -41,10 +41,17 @@ radio.onDataReceived(() => {
});
```
Sample output to serial when ``A`` button pressed:
```{v:27,t:323,s:0}```
```Text
{v:27,t:323,s:0}
```
### See also
[send number](/reference/radio/send-number),
[send value](/reference/radio/send-value),
[on data received](/reference/radio/on-data-received)
```package
microbit-radio
```

View File

@ -5,8 +5,12 @@ Reading and writing data over a serial connection.
```cards
serial.writeLine("");
serial.writeNumber(0);
serial.writeValue(x, 0);
serial.writeValue("x", 0);
serial.writeString("");
serial.readLine();
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
```
### See Also
[writeLine](/reference/serial/write-line), [writeNumber](/reference/serial/write-number), [writeValue](/reference/serial/write-value), [writeString](/reference/serial/write-string), [readLine](/reference/serial/read-line), [redirect](/reference/serial/redirect-to)

View File

@ -0,0 +1,16 @@
# Boolean
true or false.
A Boolean has one of two possible values: `true`; `false`. Boolean (logical) operators (*and*, *or*, *not*) take Boolean inputs and yields a Boolean value. Comparison operators on other types ([numbers](/reference/types/number), [strings](/reference/types/string) yields a Boolean value.
The following blocks represent the true and false Boolean values, which can be plugged in anywhere a Boolean value is expected:
```blocks
true;
false;
```
### See Also
[boolean (blocks)](/blocks/logic/boolean.md)

View File

@ -1,9 +1,16 @@
# Release notes
### @description Editor release notes
```sim
basic.forever(() => { basic.showString("RELEASE NOTES"); });
```
## August 2016
* The JavaScript editor is using Monaco
* New [package system](/packages) based on GitHub
## June 2016
* It is now possible to stream data into the cloud (Azure) from the PXT editor. Simply click on the log view to get started.

View File

@ -1,3 +1,5 @@
# Support
Please use the [GitHub issue tracker](https://github.com/microsoft/pxt-microbit) to report bugs.
Send us your feedback and ideas on our [User Voice Forum](https://touchdevelop.uservoice.com/forums/402381-code-the-micro-bit/).
You can also use our [GitHub issue tracker](https://github.com/microsoft/pxt-microbit) to report bugs.

View File

@ -1,9 +0,0 @@
# You completed the survey!
```sim
basic.forever(() => { basic.showString("THANK YOU") })
```
Thank you for participating in this survey.
Please [contact us](mailto:microbitpilots@microsoft.com) with any information you think we might find useful.

28
docs/translate.md Normal file
View File

@ -0,0 +1,28 @@
# Help translate
Our translations are managed via Crowdin, a translation management platform. It is free to join
and you can volunteer to translate parts of the web site.
## Translating the editor interface
The project below contains the resources from https://www.pxt.io and the menu items of https://codethemicrobit.com.
* [https://crowdin.com/project/kindscript](https://crowdin.com/project/kindscript)
You will find two files in that project:
* ``string.json``: text contained in the menu items of https://codethemicrobit.com
* ``website.json``: text contained in the pages served by https://www.pxt.io
## Translating the blocks and reference documentation
The project below contains the resources from the blocks and functions using in the https://codethemicrobit.com.
* [https://crowdin.com/project/pxt-microbit](https://crowdin.com/project/pxt-microbit)
You will find two files for each package available in the micro:bit, one for the block definition and one for the descriptions:
* ``microbit-strings.json``: contains the block definitions
* ``microbit-jsdoc-strings.json``: contains the descriptions
The block definition should be carefully translated using the [block definition syntax](https://www.pxt.io/defining-blocks).

View File

@ -1,5 +1,7 @@
# Uploader
### @description A Windows application that automatically deploys .hex files to connected micro:bit boards
### ~avatar avatar
The Uploader **automatically** deploys .hex files to all micro:bits connected to your computer.

View File

@ -1,12 +0,0 @@
# Windows 10 App
## Features
The Windows 10 App provides all the existing features of [codethemicrobit](https://codethemicrobit.com) 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.
## Installing the app
Coming to the store soon!

View File

@ -8,6 +8,6 @@
"public": true,
"additionalFilePath": "../../node_modules/pxt-core/libs/lang-test0",
"dependencies": {
"microbit": "file:../microbit"
"microbit": "*"
}
}

View File

@ -22,6 +22,7 @@ console.log("Starting...")
basic.showNumber(0);
testBuffer()
testBufferShiftRotate()
basic.showNumber(2);
console.log("ALL TESTS OK")
@ -75,3 +76,63 @@ function testBuffer() {
b.shift(-1)
bufferIs(b, [0, 4, 13]);
}
function testBufferShiftRotate() {
let b = pins.createBuffer(5);
function initb() {
for (let i = 0; i < b.length; ++i) {
b[i] = i;
}
}
function assertb(ex: number[]) {
bufferIs(b, ex)
}
initb()
assertb([0, 1, 2, 3, 4])
//shifting
initb()
b.shift(-1);
assertb([0, 0, 1, 2, 3])
initb()
b.shift(-1, 0, 3);
assertb([0, 0, 1, 3, 4])
initb()
b.shift(-1, 1, 3);
assertb([0, 0, 1, 2, 4])
initb()
b.shift(1)
assertb([1, 2, 3, 4, 0])
initb()
b.shift(1, 1, 3)
assertb([0, 2, 3, 0, 4])
//rotating
initb()
b.rotate(-1);
assertb([4, 0, 1, 2, 3])
initb()
b.rotate(-1, 0, 3);
assertb([2, 0, 1, 3, 4])
initb()
b.rotate(-1, 1, 3);
assertb([0, 3, 1, 2, 4])
initb()
b.rotate(2)
assertb([2, 3, 4, 0, 1])
initb()
b.rotate(1, 1, 3)
assertb([0, 2, 3, 1, 4])
}

View File

@ -7,6 +7,6 @@
],
"public": true,
"dependencies": {
"microbit": "file:../microbit"
"microbit": "*"
}
}

View File

@ -0,0 +1,15 @@
{
"bluetooth": "Support for additional Bluetooth services.",
"bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth",
"bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established",
"bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost",
"bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost",
"bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service",
"bluetooth.startButtonService": "Starts the Bluetooth button service",
"bluetooth.startIOPinService": "Starts the Bluetooth IO pin service.",
"bluetooth.startLEDService": "Starts the Bluetooth LED service",
"bluetooth.startMagnetometerService": "Starts the Bluetooth magnetometer service",
"bluetooth.startTemperatureService": "Starts the Bluetooth temperature service",
"bluetooth.uartRead": "Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.",
"bluetooth.uartWrite": "Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device."
}

View File

@ -1,26 +1,13 @@
{
"bluetooth": "Support for additional Bluetooth services.",
"bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth",
"bluetooth.onBluetoothConnected|block": "on bluetooth connected",
"bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established",
"bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost",
"bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",
"bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost",
"bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service",
"bluetooth.startAccelerometerService|block": "bluetooth accelerometer service",
"bluetooth.startButtonService": "Starts the Bluetooth button service",
"bluetooth.startButtonService|block": "bluetooth button service",
"bluetooth.startIOPinService": "Starts the Bluetooth IO pin service.",
"bluetooth.startIOPinService|block": "bluetooth io pin service",
"bluetooth.startLEDService": "Starts the Bluetooth LED service",
"bluetooth.startLEDService|block": "bluetooth led service",
"bluetooth.startMagnetometerService": "Starts the Bluetooth magnetometer service",
"bluetooth.startMagnetometerService|block": "bluetooth magnetometer service",
"bluetooth.startTemperatureService": "Starts the Bluetooth temperature service",
"bluetooth.startTemperatureService|block": "bluetooth temperature service",
"bluetooth.uartRead": "Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.",
"bluetooth.uartRead|block": "bluetooth uart read %del=bluetooth_uart_delimiter_conv",
"bluetooth.uartWrite": "Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.",
"bluetooth.uartWrite|block": "bluetooth uart write %data",
"bluetooth|block": "bluetooth"
}

View File

@ -84,8 +84,8 @@ namespace bluetooth {
/**
* Starts the Bluetooth UART service
*/
// help=bluetooth/start-uart-service
// blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
//% help=bluetooth/start-uart-service
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
void startUartService() {
if (uart) return;
// 61 octet buffer size is 3 x (MTU - 3) + 1

View File

@ -49,6 +49,13 @@ declare namespace bluetooth {
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 shim=bluetooth::startButtonService
function startButtonService(): void;
/**
* Starts the Bluetooth UART service
*/
//% help=bluetooth/start-uart-service
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 shim=bluetooth::startUartService
function startUartService(): void;
/**
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
*/

View File

@ -0,0 +1,18 @@
{
"devices": "Control a phone with the BBC micro:bit via Bluetooth.",
"devices.onGamepadButton": "Register code to run when the micro:bit receives a command from the paired gamepad.",
"devices.onGamepadButton|param|body": "code to run when button is pressed",
"devices.onGamepadButton|param|name": "button name",
"devices.onNotified": "Registers code to run when the device notifies about a particular event.",
"devices.onNotified|param|body": "code handler when event is triggered",
"devices.onNotified|param|event": "event description",
"devices.onSignalStrengthChanged": "Registers code to run when the device notifies about a change of signal strength.",
"devices.onSignalStrengthChanged|param|body": "Code run when the signal strength changes.",
"devices.raiseAlertTo": "Sends an ``alert`` command to the parent device.",
"devices.raiseAlertTo|param|event": "event description",
"devices.signalStrength": "Returns the last signal strength reported by the paired device.",
"devices.tellCameraTo": "Sends a ``camera`` command to the parent device.",
"devices.tellCameraTo|param|event": "event description",
"devices.tellRemoteControlTo": "Sends a ``remote control`` command to the parent device.",
"devices.tellRemoteControlTo|param|event": "event description"
}

View File

@ -1,26 +1,10 @@
{
"devices": "Control a phone with the BBC micro:bit via Bluetooth.",
"devices.onGamepadButton": "Register code to run when the micro:bit receives a command from the paired gamepad.",
"devices.onGamepadButton|block": "on gamepad button|%NAME",
"devices.onGamepadButton|param|body": "code to run when button is pressed",
"devices.onGamepadButton|param|name": "button name",
"devices.onNotified": "Registers code to run when the device notifies about a particular event.",
"devices.onNotified|block": "on notified|%event",
"devices.onNotified|param|body": "code handler when event is triggered",
"devices.onNotified|param|event": "event description",
"devices.onSignalStrengthChanged": "Registers code to run when the device notifies about a change of signal strength.",
"devices.onSignalStrengthChanged|block": "on signal strength changed",
"devices.onSignalStrengthChanged|param|body": "Code run when the signal strength changes.",
"devices.raiseAlertTo": "Sends an ``alert`` command to the parent device.",
"devices.raiseAlertTo|block": "raise alert to|%property",
"devices.raiseAlertTo|param|event": "event description",
"devices.signalStrength": "Returns the last signal strength reported by the paired device.",
"devices.signalStrength|block": "signal strength",
"devices.tellCameraTo": "Sends a ``camera`` command to the parent device.",
"devices.tellCameraTo|block": "tell camera to|%property",
"devices.tellCameraTo|param|event": "event description",
"devices.tellRemoteControlTo": "Sends a ``remote control`` command to the parent device.",
"devices.tellRemoteControlTo|block": "tell remote control to|%property",
"devices.tellRemoteControlTo|param|event": "event description",
"devices|block": "devices"
}

View File

@ -0,0 +1,19 @@
{
"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.receivedNumberAt|param|index": "index of the number to read from 0 to 3. 1 eg",
"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 micro:bit in the group.",
"radio.sendValue|param|name": "the field name (max 12 characters), eg: \"data\"",
"radio.sendValue|param|value": "the numberic value",
"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.setTransmitPower|param|power": "a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7",
"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"
}

View File

@ -1,32 +1,15 @@
{
"radio": "Communicate data using radio packets",
"radio.onDataReceived": "Registers code to run when a packet is received over radio.",
"radio.onDataReceived|block": "on data received",
"radio.receiveNumber": "Reads the next packet as a number from the radio queue.",
"radio.receiveNumber|block": "receive number",
"radio.receiveString": "Reads the next packet as a string and returns it.",
"radio.receiveString|block": "receive string",
"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.receivedNumberAt|block": "receive number|at %VALUE",
"radio.receivedNumberAt|param|index": "index of the number to read from 0 to 3. 1 eg",
"radio.receivedSignalStrength": "Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.\nnamespace=radio",
"radio.receivedSignalStrength|block": "received signal strength",
"radio.sendNumber": "Broadcasts a number over radio to any connected micro:bit in the group.",
"radio.sendNumber|block": "send number %value",
"radio.sendString": "Broadcasts a number over radio to any connected micro:bit in the group.",
"radio.sendString|block": "send string %msg",
"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.sendValue|block": "send|value %name|= %value",
"radio.sendValue|param|name": "the field name (max 12 characters), eg: \"data\"",
"radio.sendValue|param|value": "the numberic value",
"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.setGroup|block": "set group %ID",
"radio.setTransmitPower": "Change the output power level of the transmitter to the given value.",
"radio.setTransmitPower|block": "set transmit power %power",
"radio.setTransmitPower|param|power": "a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7",
"radio.setTransmitSerialNumber": "Set the radio to transmit the serial number in each message.",
"radio.setTransmitSerialNumber|block": "set tranmist serial number %transmit",
"radio.writeValueToSerial": "Reads a value sent with `stream value` and writes it\nto the serial stream as JSON",
"radio.writeValueToSerial|block": "write value to serial",
"radio.onDataReceived|block": "radio on data received",
"radio.receiveNumber|block": "radio receive number",
"radio.receiveString|block": "radio receive string",
"radio.receivedNumberAt|block": "radio receive number|at %VALUE",
"radio.receivedSignalStrength|block": "radio received signal strength",
"radio.sendNumber|block": "radio send number %value",
"radio.sendString|block": "radio send string %msg",
"radio.sendValue|block": "radio send|value %name|= %value",
"radio.setGroup|block": "radio set group %ID",
"radio.setTransmitPower|block": "radio set transmit power %power",
"radio.setTransmitSerialNumber|block": "radio set transmit serial number %transmit",
"radio.writeValueToSerial|block": "radio write value to serial",
"radio|block": "radio"
}

View File

@ -114,19 +114,19 @@ namespace radio {
uBit.serial.send("{");
if (length >= 4) {
memcpy(&value, bytes, 4);
uBit.serial.send("v:"); uBit.serial.send(value);
uBit.serial.send("\"v\":"); uBit.serial.send(value);
if(length >= 8) {
memcpy(&value, bytes + 4, 4);
uBit.serial.send(",t:"); uBit.serial.send(value);
uBit.serial.send(",\"t\":"); uBit.serial.send(value);
if (length >= 12) {
memcpy(&value, bytes + 8, 4);
uBit.serial.send(",s:"); uBit.serial.send(value);
uBit.serial.send(",\"s\":"); uBit.serial.send(value);
if (length >= 13) {
char name[MAX_FIELD_NAME_LENGTH+1];
uint8_t len = min(MAX_FIELD_NAME_LENGTH, bytes[12]);
memcpy(name, bytes + 13, len);
name[len] = 0;
uBit.serial.send(",n:\""); uBit.serial.send(name); uBit.serial.send("\"");
uBit.serial.send(",\"n\":\""); uBit.serial.send(name); uBit.serial.send("\"");
}
}
}
@ -134,16 +134,6 @@ namespace radio {
uBit.serial.send("}\r\n");
}
/**
* Registers code to run when a packet is received over radio.
*/
//% help=radio/on-data-received
//% weight=50
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8
void onDataReceived(Action body) {
if (radioEnable() != MICROBIT_OK) return;
registerWithDal(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, body);
}
/**
* Reads a number at a given index, between ``0`` and ``3``, from the packet received by ``receive number``. Not supported in simulator.
@ -162,7 +152,7 @@ namespace radio {
}
return 0;
}
/**
* Reads the next packet as a number from the radio queue.
*/
@ -175,6 +165,20 @@ namespace radio {
packet = uBit.radio.datagram.recv();
return receivedNumberAt(0);
}
/**
* Registers code to run when a packet is received over radio.
*/
//% help=radio/on-data-received
//% weight=50
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8
void onDataReceived(Action body) {
if (radioEnable() != MICROBIT_OK) return;
registerWithDal(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, body);
// make the the receive buffer has a free spot
receiveNumber();
}
/**
* Reads the next packet as a string and returns it.
@ -231,6 +235,7 @@ namespace radio {
//% weight=8 blockGap=8
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit"
void setTransmitSerialNumber(bool transmit) {
if (radioEnable() != MICROBIT_OK) return;
transmitSerialNumber = transmit;
}
}

View File

@ -41,14 +41,6 @@ declare namespace radio {
//% blockId=radio_write_value_serial block="radio write value to serial" shim=radio::writeValueToSerial
function writeValueToSerial(): void;
/**
* Registers code to run when a packet is received over radio.
*/
//% help=radio/on-data-received
//% weight=50
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8 shim=radio::onDataReceived
function onDataReceived(body: () => void): void;
/**
* Reads a number at a given index, between ``0`` and ``3``, from the packet received by ``receive number``. Not supported in simulator.
* @param index index of the number to read from 0 to 3. 1 eg
@ -66,6 +58,14 @@ declare namespace radio {
//% blockId=radio_datagram_receive block="radio receive number" blockGap=8 shim=radio::receiveNumber
function receiveNumber(): number;
/**
* Registers code to run when a packet is received over radio.
*/
//% help=radio/on-data-received
//% weight=50
//% blockId=radio_datagram_received_event block="radio on data received" blockGap=8 shim=radio::onDataReceived
function onDataReceived(body: () => void): void;
/**
* Reads the next packet as a string and returns it.
*/

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