Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d1b91afc3 | |||
5c0d37d718 | |||
c81e56613e | |||
4cc7215d35 | |||
8751d2aaa1 | |||
af91622dda | |||
45d4caf595 | |||
5099b11823 | |||
37e0307698 | |||
1b15eefa5a | |||
a4eccaf4f9 | |||
5981863e3f | |||
9ac7a4c522 | |||
9f1c3ee13c | |||
8b9c3d71d5 | |||
6d726b7499 | |||
b5da5afd1d | |||
420898e98c | |||
f6b392356c | |||
f4896f8d7c | |||
4dbd691146 | |||
2742dba0c4 | |||
5bea47a094 | |||
835a4b5cf0 | |||
055704b3ef | |||
60107aa7ce |
@ -33,9 +33,16 @@ If you are using the Google Chrome browser, you can use our extension to get ser
|
||||
|
||||
### Windows
|
||||
|
||||
You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it:
|
||||
You must install a device driver (for the computer to recognize the
|
||||
serial interface of the micro:bit); then, you must also install a
|
||||
terminal emulator (which is going to connect to the micro:bit and read
|
||||
its output).
|
||||
|
||||
* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver
|
||||
* Follow the instructions at
|
||||
https://developer.mbed.org/handbook/Windows-serial-configuration to
|
||||
install the device driver.
|
||||
|
||||
* Instructions for installing a terminal emulator are below.
|
||||
|
||||
#### Windows > Tera Term
|
||||
|
||||
@ -66,14 +73,16 @@ If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/))
|
||||
|
||||
### Linux
|
||||
|
||||
(Untested).
|
||||
* Install the program `screen` if it is not already installed.
|
||||
* Plug in the micro:bit.
|
||||
* Open a terminal.
|
||||
* Find which device node the micro:bit was assigned to with the command `ls /dev/ttyACM*`.
|
||||
* If it was `/dev/ttyACM0`, type the command `screen /dev/ttyACM0 115200`. If it was some other device node,
|
||||
use that one in the command instead. **Note:** You may need root access to run `screen`
|
||||
successfully. You can probably use the command `sudo` like this: `sudo screen /dev/ttyACM0 115200`.
|
||||
* To exit `screen`, type `Ctrl-A` `Ctrl-D`.
|
||||
|
||||
* Plug in the micro:bit
|
||||
* Open a terminal
|
||||
* `dmesg | tail` will show you which `/dev/` node the micro:bit was assigned (e.g. `/dev/ttyUSB0`)
|
||||
* Then, do: `screen /dev/ttyUSB0 115200` (install the `screen` program if you don't have it). To exit, run `Ctrl-A` `Ctrl-D`.
|
||||
|
||||
Alternative programs include minicom, etc.
|
||||
Alternative programs include `minicom` and so on.
|
||||
|
||||
### Mac OS
|
||||
|
||||
|
@ -1,75 +1,15 @@
|
||||
# JavaScript
|
||||
|
||||
You can write micro:bit programs in a subset of [TypeScript](https://www.typescriptlang.org), a superset of JavaScript.
|
||||
Many micro:bit programs, especially at the beginner's level, are just plain JavaScript. TypeScript introduces class-based
|
||||
object-oriented programming, such as:
|
||||
If you already know some JavaScript, you might be interested in [the JavaScript and TypeScript languages](/js/lang).
|
||||
Otherwise, visit the cards below to starting programming JavaScript with the micro:bit:
|
||||
|
||||
```typescript
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
```codecard
|
||||
[{
|
||||
"name": "Calling Functions",
|
||||
"url":"/js/call"
|
||||
},{
|
||||
"name": "Sequencing Commands",
|
||||
"url":"/js/sequence"
|
||||
}
|
||||
|
||||
let greeter = new Greeter("world");
|
||||
basic.showString(greeter.greet())
|
||||
```
|
||||
|
||||
This site is meant for teaching programming first, and JavaScript second. For this
|
||||
reason, we have stayed away from concepts that are specific to JavaScript (for
|
||||
example, prototype inheritance), and instead focused on ones common to most
|
||||
modern programming languages (for example, loops, lexically scoped variables,
|
||||
functions, classes, lambdas).
|
||||
|
||||
We leverage TypeScript's [type inference](http://www.typescriptlang.org/docs/handbook/type-inference.html) so that
|
||||
students need not specify types when clear from context.
|
||||
|
||||
## Supported language features
|
||||
|
||||
* top-level code in the file: "Hello world!" really is just `basic.showString("Hello world!")`
|
||||
* [basic types](http://www.typescriptlang.org/docs/handbook/basic-types.html)
|
||||
* [variable declarations](http://www.typescriptlang.org/docs/handbook/variable-declarations.html): `let`, `const`, and `var`
|
||||
* [functions](http://www.typescriptlang.org/docs/handbook/functions.html) with lexical scoping and recursion
|
||||
|
||||
### User-defined types and modules
|
||||
|
||||
* [classes](http://www.typescriptlang.org/docs/handbook/classes.html) with fields, methods and constructors; `new` keyword
|
||||
* [enums](http://www.typescriptlang.org/docs/handbook/enums.html)
|
||||
* [namespaces](http://www.typescriptlang.org/docs/handbook/namespaces.html) (a form of modules)
|
||||
|
||||
### Control-flow constructs
|
||||
|
||||
* `if ... else if ... else` statements
|
||||
* `while` and `do ... while` loops
|
||||
* `for(;;)` loops (see below about `for ... in/of`)
|
||||
* `break/continue`; also with labeled loops
|
||||
* `switch` statement (on numbers only)
|
||||
* `debugger` statement for breakpoints
|
||||
|
||||
### Expressions
|
||||
|
||||
* conditional operator `? :`; lazy boolean operators
|
||||
* all arithmetic operators (including bitwise operators); note that in microcontroller targets
|
||||
all arithmetic is performed on integers, also when simulating in the browser
|
||||
* strings (with a few common methods)
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
* arrow functions `() => ...`
|
||||
* array literals `[1, 2, 3]`
|
||||
|
||||
|
||||
## Unsupported language features
|
||||
|
||||
We generally stay away from the more dynamic parts of JavaScript.
|
||||
Things you may miss and we may implement:
|
||||
|
||||
* exceptions (`throw`, `try ... catch`, `try ... finally`)
|
||||
* `for ... of` statements
|
||||
* object literals `{ foo: 1, bar: "two" }`
|
||||
* method-like properties (get/set accessors)
|
||||
* class inheritance
|
||||
|
||||
If there is something you'd like to see, please file an issue at [GitHub](http://github.com/microsoft/pxt/issues).
|
||||
]
|
||||
```
|
@ -3,56 +3,56 @@
|
||||
The simplest way to get started in JavaScript with your micro:bit is to
|
||||
call one of the micro:bit's built-in JavaScript functions. Just like Blocks
|
||||
are organized into categories/drawers, the micro:bit functions are organized by
|
||||
namespaces. The `basic` namespace contains a number of very helpful
|
||||
functions:
|
||||
namespaces, with names corresponding to the drawer names.
|
||||
The `basic` namespace contains a number of very helpful functions:
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!")
|
||||
```
|
||||
|
||||
If you want to see all functions available in a namespace, simply type `basic`
|
||||
followed by `.`; a list of all the functions will appear.
|
||||
If you want to see all functions available in the `basic` namespace, simply type `basic`
|
||||
followed by `.` and a list of all the functions will appear.
|
||||
|
||||

|
||||
|
||||
Continue typing to select one of the functions, or click on one of the functions
|
||||
to select. You also narrow down the set of functions by typing, as below:
|
||||
This feature is known as "Intellisense". Continue typing to select one of the functions,
|
||||
or click on one of the functions to select. You also narrow down the set of functions by typing, as below:
|
||||
|
||||

|
||||
|
||||
# Function parameters
|
||||
You can type anything to see what Intellisense will find for you. Here's an example
|
||||
of what happens when you type the word `for`:
|
||||

|
||||
|
||||
You might have noticed that the call `showString` above takes one value,
|
||||
## Function parameter values
|
||||
|
||||
You might have noticed that the call `showString` above takes one parameter value,
|
||||
the string to be scrolled on the LED screen. There is a second (optional)
|
||||
parameter that controls the speed of the the scroll. Try this:
|
||||
parameter that controls the speed of the scroll. Try this:
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!",50)
|
||||
```
|
||||
|
||||
You might have noticed that the function list above shows all
|
||||
the available parameters for each function.
|
||||
Intellisense shows all the available parameters for a function.
|
||||
|
||||
## Left and right parentheses, please!
|
||||
|
||||
Whenever you want to call a function, you give the name of the function
|
||||
followed by `(` and ending with `)`. Inbetween the left and right
|
||||
parentheses go the function arguments. If a function has zero arguments, you still
|
||||
need the parentheses in order to call the function. For example
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!")
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.clearScreen()
|
||||
basic.showString("Goodbye!")
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.clearScreen()
|
||||
```
|
||||
```
|
||||
|
||||
It's a syntax error to have a left parenthesis without the "closing" right parenthesis:
|
||||
|
||||
```typescript
|
||||
basic.clearScreen(
|
||||
```
|
||||
|
||||
### ~button /js/sequence
|
||||
NEXT: Sequencing Commands
|
||||
### ~
|
||||
|
75
docs/js/lang.md
Normal file
75
docs/js/lang.md
Normal file
@ -0,0 +1,75 @@
|
||||
# JavaScript and TypeScript
|
||||
|
||||
You can write micro:bit programs in a subset of [TypeScript](https://www.typescriptlang.org), a superset of JavaScript.
|
||||
Many micro:bit programs, especially at the beginner's level, are just plain JavaScript. TypeScript introduces class-based
|
||||
object-oriented programming, such as:
|
||||
|
||||
```typescript
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
}
|
||||
|
||||
let greeter = new Greeter("world");
|
||||
basic.showString(greeter.greet())
|
||||
```
|
||||
|
||||
This site is meant for teaching programming first, and JavaScript second. For this
|
||||
reason, we have stayed away from concepts that are specific to JavaScript (for
|
||||
example, prototype inheritance), and instead focused on ones common to most
|
||||
modern programming languages (for example, loops, lexically scoped variables,
|
||||
functions, classes, lambdas).
|
||||
|
||||
We leverage TypeScript's [type inference](http://www.typescriptlang.org/docs/handbook/type-inference.html) so that
|
||||
students need not specify types when clear from context.
|
||||
|
||||
## Supported language features
|
||||
|
||||
* top-level code in the file: "Hello world!" really is just `basic.showString("Hello world!")`
|
||||
* [basic types](http://www.typescriptlang.org/docs/handbook/basic-types.html)
|
||||
* [variable declarations](http://www.typescriptlang.org/docs/handbook/variable-declarations.html): `let`, `const`, and `var`
|
||||
* [functions](http://www.typescriptlang.org/docs/handbook/functions.html) with lexical scoping and recursion
|
||||
|
||||
### User-defined types and modules
|
||||
|
||||
* [classes](http://www.typescriptlang.org/docs/handbook/classes.html) with fields, methods and constructors; `new` keyword
|
||||
* [enums](http://www.typescriptlang.org/docs/handbook/enums.html)
|
||||
* [namespaces](http://www.typescriptlang.org/docs/handbook/namespaces.html) (a form of modules)
|
||||
|
||||
### Control-flow constructs
|
||||
|
||||
* `if ... else if ... else` statements
|
||||
* `while` and `do ... while` loops
|
||||
* `for(;;)` loops (see below about `for ... in/of`)
|
||||
* `break/continue`; also with labeled loops
|
||||
* `switch` statement (on numbers only)
|
||||
* `debugger` statement for breakpoints
|
||||
|
||||
### Expressions
|
||||
|
||||
* conditional operator `? :`; lazy boolean operators
|
||||
* all arithmetic operators (including bitwise operators); note that in microcontroller targets
|
||||
all arithmetic is performed on integers, also when simulating in the browser
|
||||
* strings (with a few common methods)
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
* arrow functions `() => ...`
|
||||
* array literals `[1, 2, 3]`
|
||||
|
||||
|
||||
## Unsupported language features
|
||||
|
||||
We generally stay away from the more dynamic parts of JavaScript.
|
||||
Things you may miss and we may implement:
|
||||
|
||||
* exceptions (`throw`, `try ... catch`, `try ... finally`)
|
||||
* `for ... of` statements
|
||||
* object literals `{ foo: 1, bar: "two" }`
|
||||
* method-like properties (get/set accessors)
|
||||
* class inheritance
|
||||
|
||||
If there is something you'd like to see, please file an issue at [GitHub](http://github.com/microsoft/pxt/issues).
|
25
docs/js/sequence.md
Normal file
25
docs/js/sequence.md
Normal file
@ -0,0 +1,25 @@
|
||||
## Sequencing commands
|
||||
|
||||
By calling one function after another, you can create an animation:
|
||||
|
||||
```typescript
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
```
|
||||
|
||||
## The Semicolon
|
||||
|
||||
Coming soon...
|
||||
|
37
docs/reference/game/create-sprite.md
Normal file
37
docs/reference/game/create-sprite.md
Normal file
@ -0,0 +1,37 @@
|
||||
# Create Sprite
|
||||
|
||||
Create a new LED sprite pointing to the right.
|
||||
|
||||
A sprite is like a little LED creature you can tell what to do.
|
||||
You can tell it to move, turn, and check whether it has bumped
|
||||
into another sprite.
|
||||
|
||||
```sig
|
||||
game.createSprite(2, 2);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``x``: The left-to-right place on the LED screen where the sprite will start out.
|
||||
* ``y``: The top-to-bottom place on the LED screen where the sprite will start out.
|
||||
|
||||
`0` and `4` mean the edges of the screen, and `2` means in the middle.
|
||||
|
||||
### Example
|
||||
|
||||
This program starts a sprite in the middle of the screen.
|
||||
Next, the sprite turns toward the lower-right corner.
|
||||
Finally, it moves two LEDs away to the corner.
|
||||
|
||||
```blocks
|
||||
let item = game.createSprite(2, 2);
|
||||
item.turn(Direction.Right, 45);
|
||||
item.move(2);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[move](/reference/game/move),
|
||||
[turn](/reference/game/turn),
|
||||
[touching](/reference/game/touching)
|
||||
|
@ -1,7 +1,24 @@
|
||||
# Move
|
||||
|
||||
Sprite move by a certain number of LEDs
|
||||
Move the sprite the number of LEDs you say.
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``move by`` is a [number](/reference/types/number) that means how many LEDs the sprite should move
|
||||
|
||||
### Example
|
||||
|
||||
This program starts a sprite in the middle of the screen.
|
||||
Next, the sprite turns toward the lower-right corner.
|
||||
Finally, it moves two LEDs away to the corner.
|
||||
|
||||
```blocks
|
||||
let item = game.createSprite(2, 2);
|
||||
item.turn(Direction.Right, 45);
|
||||
item.move(2);
|
||||
```
|
||||
export function move(_this: micro_bitSprites.LedSprite, leds: number)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[turn](/reference/game/turn),
|
||||
[create sprite](/reference/game/create-sprite)
|
||||
|
@ -2,7 +2,12 @@
|
||||
|
||||
Reports true if sprite is touching specified sprite
|
||||
|
||||
```blocks
|
||||
let matter = game.createSprite(2, 2);
|
||||
let antimatter = game.createSprite(2, 2);
|
||||
if (matter.isTouching(antimatter)) {
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.showString("BOOM!");
|
||||
}
|
||||
```
|
||||
export function isTouching(_this: micro_bitSprites.LedSprite, other: micro_bitSprites.LedSprite) : boolean
|
||||
```
|
||||
|
||||
|
@ -1,14 +1,28 @@
|
||||
# Turn
|
||||
|
||||
Rotates a sprite to the right by a certain number of degrees
|
||||
Turn the sprite as much as you say in the direction you say.
|
||||
|
||||
```
|
||||
export function turnRight(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
### Parameters
|
||||
|
||||
* ``turn`` is a choice whether the sprite should turn **left** or **right**
|
||||
* ``by`` is a [number](/reference/types/number) that means how much the sprite should turn.
|
||||
This number is in **degrees**, so a straight left or right turn is 90 degrees.
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
This program starts a sprite in the middle of the screen.
|
||||
Next, the sprite turns toward the lower-right corner.
|
||||
Finally, it moves two LEDs away to the corner.
|
||||
|
||||
```blocks
|
||||
let item = game.createSprite(2, 2);
|
||||
item.turn(Direction.Right, 45);
|
||||
item.move(2);
|
||||
```
|
||||
|
||||
Rotates a sprite to the left by a certain number of degrees
|
||||
### See also
|
||||
|
||||
```
|
||||
export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
```
|
||||
|
||||
[move](/reference/game/move),
|
||||
[create sprite](/reference/game/create-sprite)
|
||||
|
@ -1,8 +1,22 @@
|
||||
# Stop Animation
|
||||
|
||||
Cancels the current animation and clears other pending animations .
|
||||
Stop the animation that is playing and any animations that are waiting to
|
||||
play.
|
||||
|
||||
```sig
|
||||
led.stopAnimation()
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program...
|
||||
|
||||
```blocks
|
||||
basic.showString("STOP ME! STOP ME! PLEASE, WON'T SOMEBODY STOP ME?");
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
led.stopAnimation();
|
||||
});
|
||||
'```
|
||||
### See Also
|
||||
|
||||
|
||||
|
32
docs/reference/pins/i2c-read-number.md
Normal file
32
docs/reference/pins/i2c-read-number.md
Normal file
@ -0,0 +1,32 @@
|
||||
# I2C Read Number
|
||||
|
||||
Read one number from the specified 7-bit I2C address, in the specified
|
||||
number format.
|
||||
|
||||
```sig
|
||||
pins.i2cReadNumber(0, NumberFormat.Int8LE);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``address``: the 7-bit I2C address from which to read the number.
|
||||
* ``format``: the number format. Formats include
|
||||
**Int8LE**, **UInt8LE**, **Int16LE**, **UInt16LE**, **Int32LE**,
|
||||
**Int8BE**, **UInt8BE**, **Int16BE**, **UInt16BE**, and
|
||||
**Int32BE**.
|
||||
* **Int** stands for "integer", and **UInt** stands for "unsigned integer".
|
||||
* **LE** stands for "little-endian" and **BE** stands for "big-endian".
|
||||
* The number in each format name stands for the number of bits in the format.
|
||||
|
||||
### Example
|
||||
|
||||
The following example reads a number in big-endian, 16-bit, unsigned integer
|
||||
format from the 7-bit I2C address `32`.
|
||||
|
||||
```blocks
|
||||
pins.i2cReadNumber(32, NumberFormat.UInt16BE);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)
|
32
docs/reference/pins/i2c-write-number.md
Normal file
32
docs/reference/pins/i2c-write-number.md
Normal file
@ -0,0 +1,32 @@
|
||||
# I2C Write Number
|
||||
|
||||
Write the specified number to the specified 7-bit I2C address in the
|
||||
specified number format.
|
||||
|
||||
```sig
|
||||
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``address``: the 7-bit I2C address to which to send ``value``
|
||||
* ``value``: the number to send to ``address``
|
||||
* ``format``: the number format for ``value``. Formats include
|
||||
**Int8LE**, **UInt8LE**, **Int16LE**, **UInt16LE**, **Int32LE**,
|
||||
**Int8BE**, **UInt8BE**, **Int16BE**, **UInt16BE**, and
|
||||
**Int32BE**.
|
||||
* **Int** stands for "integer", and **UInt** stands for "unsigned integer".
|
||||
* **LE** stands for "little-endian" and **BE** stands for "big-endian".
|
||||
* The number in each format name stands for the number of bits in the format.
|
||||
|
||||
### Example
|
||||
|
||||
The following example sends the value `2055` to the 7-bit I2C
|
||||
address `32` in big-endian 32-bit integer format.
|
||||
|
||||
```blocks
|
||||
pins.i2cWriteNumber(32, 2055, NumberFormat.Int32BE);
|
||||
```
|
||||
### See also
|
||||
|
||||
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)
|
31
docs/reference/pins/on-pulsed.md
Normal file
31
docs/reference/pins/on-pulsed.md
Normal file
@ -0,0 +1,31 @@
|
||||
# On Pulsed
|
||||
|
||||
Configure the specified pin for digital input, and then
|
||||
execute the associated code block whenever the pin
|
||||
pulses **High** or **Low** (as specified).
|
||||
|
||||
```sig
|
||||
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => { });
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``pin``: The micro:bit hardware pin to configure (``P0`` through ``P20``)
|
||||
* ``pulsed``: Which state will cause the associated block to execute (**High** or **Low**)
|
||||
|
||||
### Example
|
||||
|
||||
The following example configures pin ``P2`` for digital input,
|
||||
and then displays the string `LOW` whenever ``P2`` pulses low.
|
||||
|
||||
```blocks
|
||||
pins.onPulsed(DigitalPin.P2, PulseValue.Low, () => {
|
||||
basic.showString("LOW");
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[servo set pulse](/reference/pins/servo-set-pulse),
|
||||
[pulse duration](/reference/pins/pulse-duration),
|
||||
[digital read pin](/reference/pins/digital-read-pin)
|
30
docs/reference/pins/pulse-duration.md
Normal file
30
docs/reference/pins/pulse-duration.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Pulse Duration
|
||||
|
||||
Gets the duration of the last pulse in microseconds.
|
||||
|
||||
This function should be called from an **on pulsed** handler.
|
||||
|
||||
```sig
|
||||
pins.pulseDuration();
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
||||
The duration of the last pulse, measured in microseconds.
|
||||
|
||||
### Example
|
||||
|
||||
The following example waits for pin ``P0`` to be pulsed high, and then
|
||||
displays the duration of the pulse in microseconds on the LED screen.
|
||||
|
||||
```blocks
|
||||
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
|
||||
basic.showNumber(pins.pulseDuration());
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[servo set pulse](/reference/pins/servo-set-pulse),
|
||||
[on pulsed](/reference/pins/on-pulsed),
|
||||
[digital read pin](/reference/pins/digital-read-pin)
|
@ -1,9 +1,12 @@
|
||||
# Servo Write Pin
|
||||
|
||||
Writes a value to the servo on to the specified [pin](/device/pins) (``P0``, ``P1``, ``P2``), controlling the shaft accordingly.
|
||||
Write a value to the servo on the specified [pin](/device/pins)
|
||||
and control the shaft.
|
||||
|
||||
* 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).
|
||||
This function will move the shaft of a standard servo to the specified
|
||||
angle, or set the speed of a continuous rotation servo. (`0` specifies
|
||||
full speed in one direction, `180` specifies full speed in the other,
|
||||
and approximately `90` specifies no movement.)
|
||||
|
||||
```sig
|
||||
pins.servoWritePin(AnalogPin.P0, 180)
|
||||
@ -11,18 +14,18 @@ pins.servoWritePin(AnalogPin.P0, 180)
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `value` - a [Number](/reference/types/number) between 0 and 180 included
|
||||
* a [string](/reference/types/string) that specifies the pin name (`P0` through `P4`, or `P10`)
|
||||
* a [number](/reference/types/number) from `0` through `180`
|
||||
|
||||
### Examples
|
||||
|
||||
* setting the shaft angle to mid point on a servo
|
||||
#### Setting the shaft angle to midpoint on a servo
|
||||
|
||||
```blocks
|
||||
pins.servoWritePin(AnalogPin.P0, 90)
|
||||
```
|
||||
|
||||
* control the shaft by using the tilt information of the accelerometer
|
||||
#### Controlling the shaft by using the tilt information of the accelerometer
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
@ -33,7 +36,7 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
* setting the full speed on a continuous servo
|
||||
#### Setting the full speed on a continuous servo
|
||||
|
||||
```blocks
|
||||
pins.servoWritePin(AnalogPin.P0, 0)
|
||||
|
32
docs/reference/pins/set-pull.md
Normal file
32
docs/reference/pins/set-pull.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Set Pull
|
||||
|
||||
Configure the electrical pull of the specified pin.
|
||||
|
||||
Many micro:bit pins can be configured as _pull-ups_. For example, a
|
||||
pull-up can set a pin's voltage to high (3.3 volts, or `1` when
|
||||
calling [digital read pin](/reference/pins/digital-read-pin)). If one
|
||||
end of a button is connected to ``P0`` (set to high) and the other end
|
||||
is connected to ``GND`` (0 volts), then when you press the button,
|
||||
``P0`` is driven to 0 volts, and the micro:bit software can detect a
|
||||
button press.
|
||||
|
||||
```sig
|
||||
pins.setPull(DigitalPin.P9, PinPullMode.PullDown);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``pin``: The micro:bit hardware pin to configure (``P0``-``P20``)
|
||||
* ``to``: The pull to which to set the pin (**down**, **up**, or **none**)
|
||||
|
||||
### Example
|
||||
|
||||
The following example sets the pull of pin ``P0`` to **up** (high).
|
||||
|
||||
```blocks
|
||||
pins.setPull(DigitalPin.P0, PinPullMode.PullUp);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit | mbed](https://developer.mbed.org/platforms/Microbit/)
|
@ -1,14 +1,32 @@
|
||||
# Write Line
|
||||
# Serial Write Line
|
||||
|
||||
Writes a string and a new line character (`\r\n`) to [serial](/device/serial).
|
||||
Write a string to the [serial](/device/serial) port and start a new line of text
|
||||
by writing `\r\n`.
|
||||
|
||||
```sig
|
||||
serial.writeLine("");
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `line` is the [string](/reference/types/string) to write to the serial port
|
||||
|
||||
### Example: simple serial
|
||||
|
||||
This program writes the word `BOFFO` to the serial port repeatedly.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
serial.writeLine("BOFFO");
|
||||
basic.pause(5000);
|
||||
});
|
||||
```
|
||||
|
||||
### Example: streaming data
|
||||
|
||||
The following example constantly checks the [compass heading](/reference/input/compass-heading) and sends the direction to serial.
|
||||
This program checks the
|
||||
[compass heading](/reference/input/compass-heading) and sends the
|
||||
direction to the serial port repeatedly.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
@ -26,8 +44,8 @@ basic.forever(() => {
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial), [write value](/reference/serial/write-value)
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write number](/reference/serial/write-number),
|
||||
[serial write value](/reference/serial/write-value)
|
||||
|
41
docs/reference/serial/write-number.md
Normal file
41
docs/reference/serial/write-number.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Serial Write Number
|
||||
|
||||
Write a number to the [serial](/device/serial) port.
|
||||
|
||||
```sig
|
||||
serial.writeNumber(0);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `number` is the [number](/reference/types/number) to write to the serial port
|
||||
|
||||
### Example: one through ten
|
||||
|
||||
This program repeatedly writes a 10-digit number to the serial port.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
serial.writeNumber(1234567890);
|
||||
basic.pause(5000);
|
||||
});
|
||||
```
|
||||
|
||||
### Example: plot bar graph does serial
|
||||
|
||||
If you use the ``led.plotBarGraph`` function, it writes the number
|
||||
being plotted to the serial port too.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.lightLevel(), 255)
|
||||
basic.pause(10000);
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Write Value
|
||||
|
||||
Writes name/value pair and a new line character (`\r\n`) to [serial](/device/serial).
|
||||
Write a name/value pair and a newline character (`\r\n`) to the [serial](/device/serial) port.
|
||||
|
||||
```sig
|
||||
serial.writeValue("x", 0);
|
||||
@ -8,7 +8,8 @@ serial.writeValue("x", 0);
|
||||
|
||||
### Example: streaming data
|
||||
|
||||
The sample below sends the temperature and light level every 10 seconds.
|
||||
Every 10 seconds, the example below sends the temperature and light level
|
||||
to the serial port.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
@ -18,19 +19,17 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
### Plot bar graph does serial!
|
||||
#### ~hint
|
||||
|
||||
If you use the `led.plotBarGraph` function, it automatically writes the value to the serial as well.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.lightLevel(), 255)
|
||||
basic.pause(10000);
|
||||
})
|
||||
```
|
||||
The [send value](/reference/radio/send-value) function broadcasts
|
||||
string/number pairs. You can use a second micro:bit to receive them,
|
||||
and then send them directly to the serial port with ``write value``.
|
||||
|
||||
#### ~
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial), [write line](/reference/serial/write-line)
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write number](/reference/serial/write-number),
|
||||
[send value](/reference/radio/send-value)
|
||||
|
BIN
docs/static/mb/js/forIntell.png
vendored
Normal file
BIN
docs/static/mb/js/forIntell.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -36,6 +36,7 @@
|
||||
"public": true,
|
||||
"dependencies": {},
|
||||
"yotta": {
|
||||
"configIsJustDefaults": true,
|
||||
"config": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.182",
|
||||
"version": "0.2.186",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.192"
|
||||
"pxt-core": "0.2.194"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user