Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c96591edd | |||
4f38658d74 | |||
6329a79ce1 | |||
befbdd32cc | |||
44688ee5d5 | |||
cc36bae97d | |||
c65bdb34af | |||
21f7ef9b55 | |||
d7250d54f8 | |||
9a36a2fc05 |
@ -9,8 +9,9 @@ basic.showNumber(0);
|
|||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
led.plot(0, 0);
|
|
||||||
music.playTone(0, 0);
|
music.playTone(0, 0);
|
||||||
|
led.plot(0, 0);
|
||||||
|
radio.sendNumber(0);
|
||||||
game.addScore(1);
|
game.addScore(1);
|
||||||
images.createImage(`
|
images.createImage(`
|
||||||
. . . . .
|
. . . . .
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Show Animation
|
# Show Animation
|
||||||
|
|
||||||
Show a series of image frames on the [LED screen](/device/screen), pausing the specified time after each frame.
|
Show a group of image frames (pictures) one after another on the [LED screen](/device/screen). It pauses the amount of time you tell it after each frame.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
basic.showAnimation(`
|
basic.showAnimation(`
|
||||||
@ -14,10 +14,14 @@ basic.showAnimation(`
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `leds` - [String](/reference/types/string); a series of LED on/off states
|
* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off, in groups one after another.
|
||||||
* `interval` - [Number](/reference/types/number); the number of milliseconds to pause after each image frame
|
* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds to pause after each image frame.
|
||||||
|
|
||||||
### Show a series of image frames
|
### Example: Animating a group of image frames
|
||||||
|
|
||||||
|
In this animation, each row is 15 spaces wide because
|
||||||
|
there are three frames in the animation, and each frame is
|
||||||
|
five spaces wide, just like the screen on the BBC micro:bit.
|
||||||
|
|
||||||
```
|
```
|
||||||
basic.showAnimation(`
|
basic.showAnimation(`
|
||||||
@ -31,13 +35,17 @@ basic.showAnimation(`
|
|||||||
|
|
||||||
### ~hint
|
### ~hint
|
||||||
|
|
||||||
If the series of images appear too fast, increase the value of the *interval* parameter.
|
If the animation is too fast, make `interval` bigger.
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
### Example: animating frames
|
### Example: animating frames with a pause
|
||||||
|
|
||||||
The following example creates an image with six frames and then shows each frame o the screen, pausing 500 milliseconds after each frame:
|
This example shows six frames on the screen, pausing 500 milliseconds after each frame.
|
||||||
|
|
||||||
|
In this animation, each row is 30 spaces wide because
|
||||||
|
there are six frames in the animation, and each frame is
|
||||||
|
five spaces wide, just like the screen.
|
||||||
|
|
||||||
```
|
```
|
||||||
basic.showAnimation(`
|
basic.showAnimation(`
|
||||||
@ -51,7 +59,7 @@ basic.showAnimation(`
|
|||||||
|
|
||||||
### ~hint
|
### ~hint
|
||||||
|
|
||||||
Use [forever](/reference/basic/forever) to continually repeat an animation
|
Use [forever](/reference/basic/forever) to show an animation over and over.
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@ basic.showLeds(`
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* ``leds`` - a series of LED on/off states that form an image (see steps below)
|
* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off.
|
||||||
* (optional) ``ms`` - [Number](/reference/types/number) - time to wait after displaying image. In blocks, ``ms`` is 400 by default.
|
* `ms` is an optional [Number](/reference/types/number) that shows how many milliseconds to wait after showing a picture.
|
||||||
|
If you are programming with blocks, `ms` starts out as 400 milliseconds.
|
||||||
|
|
||||||
### Example - Block Editor
|
### Example
|
||||||
|
|
||||||
1. Open the `basic` category and select the `show leds` blocks.
|
Open the `basic` card in the Block Editor and select the `show leds` blocks.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
@ -33,7 +34,7 @@ basic.showLeds(`
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
In JavaScript, the led off is represented by a `.` and the led on by a `#` character.
|
If you are programming in JavaScript, `#` means an LED that is turned on and `.` means an LED that is turned off.
|
||||||
|
|
||||||
### Lessons
|
### Lessons
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Show Number
|
# Show Number
|
||||||
|
|
||||||
Show a number on the [LED screen](/device/screen), one digit at a time (scrolling from left to right)
|
Show a number on the [LED screen](/device/screen). It will slide left if it has more than one digit.
|
||||||
|
|
||||||
~~~~sig
|
~~~~sig
|
||||||
basic.showNumber(2, 150)
|
basic.showNumber(2, 150)
|
||||||
@ -8,18 +8,18 @@ basic.showNumber(2, 150)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* value - a [Number](/reference/types/number)
|
* `value` is a [Number](/reference/types/number).
|
||||||
* (optional) interval (ms) - [Number](/reference/types/number); the time (in milliseconds) before scrolling by one LED; the larger the number, the slower the scroll
|
* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the `value` left by one LED each time. Bigger intervals make the sliding slower.
|
||||||
|
|
||||||
### ~
|
### Examples:
|
||||||
|
|
||||||
To display the number 10:
|
To show the number 10:
|
||||||
|
|
||||||
~~~~blocks
|
~~~~blocks
|
||||||
basic.showNumber(10)
|
basic.showNumber(10)
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
To display the number stored in the `x` variable:
|
To show the number stored in a variable:
|
||||||
|
|
||||||
~~~~blocks
|
~~~~blocks
|
||||||
let x = 1
|
let x = 1
|
||||||
@ -28,19 +28,19 @@ basic.showNumber(x)
|
|||||||
|
|
||||||
### Example: count to 5
|
### Example: count to 5
|
||||||
|
|
||||||
This example uses a [for](/reference/loops/for) loop to show numbers ``1`` through ``5`` on the screen:
|
This example uses a [for](/reference/loops/for) loop to show numbers ``0`` through ``5`` on the screen:
|
||||||
|
|
||||||
~~~~blocks
|
~~~~blocks
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
basic.showNumber(i + 1)
|
basic.showNumber(i)
|
||||||
basic.pause(200)
|
basic.pause(200)
|
||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
### Other show functions
|
### Other show functions
|
||||||
|
|
||||||
* use [show string](/reference/basic/show-string) to show a string on the screen
|
* Use [show string](/reference/basic/show-string) to show a [String](/reference/types/string) with letters on the screen.
|
||||||
* use [show animation](/reference/basic/show-animation) to show a series of images on the screen
|
* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another.
|
||||||
|
|
||||||
### Lessons
|
### Lessons
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Show String
|
# Show String
|
||||||
|
|
||||||
Show a string on the [LED screen](/device/screen) one character at a time (scrolling from left to right).
|
Show a number on the [LED screen](/device/screen). It will slide left if it is bigger than the screen.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
basic.showString("Hello!")
|
basic.showString("Hello!")
|
||||||
@ -8,18 +8,18 @@ basic.showString("Hello!")
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `text` - a [String](/reference/types/string)
|
* `text` is a [String](/reference/types/string). It can contain letters, numbers, and punctuation.
|
||||||
* (optional) `ms` - [Number](/reference/types/number); the time (in milliseconds) before scrolling left by one LED; the larger the number, the slower the scroll
|
* `ms` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the [String](/reference/types/string) left by one LED each time. Bigger intervals make the sliding slower.
|
||||||
|
|
||||||
### Examples:
|
### Examples:
|
||||||
|
|
||||||
To display Hello:
|
To show the word **Hello**:
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showString("Hello")
|
basic.showString("Hello")
|
||||||
```
|
```
|
||||||
|
|
||||||
To display the content of a string variable:
|
To show what is stored in a [String](/reference/types/string) variable:
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let s = "Hi"
|
let s = "Hi"
|
||||||
@ -28,8 +28,8 @@ basic.showString(s)
|
|||||||
|
|
||||||
### Other show functions
|
### Other show functions
|
||||||
|
|
||||||
* use [show number](/reference/basic/show-number) to show a number on the screen
|
* Use [show number](/reference/basic/show-number) to show a number on the [LED screen](/device/screen).
|
||||||
* use [show animation](/reference/basic/show-animation) to show a series of images on the screen
|
* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another.
|
||||||
|
|
||||||
### Lessons
|
### Lessons
|
||||||
|
|
||||||
|
@ -1,39 +1,9 @@
|
|||||||
# Logic
|
# Logic
|
||||||
|
|
||||||
[if](/reference/logic/if)
|
```cards
|
||||||
|
if(true) {}
|
||||||
```blocks
|
true;
|
||||||
if(true) {
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[Boolean](/reference/types/boolean) values: *true*; *false*
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
true
|
|
||||||
false
|
|
||||||
```
|
|
||||||
|
|
||||||
Boolean binary operators: *and* (conjunction); *or* (disjunction)
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
true && false;
|
true && false;
|
||||||
true || false;
|
!true;
|
||||||
```
|
1 != 0;
|
||||||
|
|
||||||
Boolean negation operator
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
!true
|
|
||||||
```
|
|
||||||
|
|
||||||
Comparison operators (=, !=, <, >, <=, >=)
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
0 == 0;
|
|
||||||
1 !- 0;
|
|
||||||
0 < 1;
|
|
||||||
1 > 0;
|
|
||||||
0 <= 1;
|
|
||||||
1 >= 0;
|
|
||||||
```
|
```
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
# If
|
# If
|
||||||
|
|
||||||
Run code based on a condition.
|
|
||||||
|
|
||||||
### @parent blocks/language
|
### @parent blocks/language
|
||||||
|
|
||||||
|
|
||||||
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
|
Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false.
|
||||||
|
|
||||||
### Block Editor
|
```blocks
|
||||||
|
if(true) {
|
||||||

|
}
|
||||||
|
```
|
||||||
|
|
||||||
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
|
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
|
||||||
|
|
||||||
### Example: adjusting screen brightness
|
### Example: adjusting screen brightness
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
if(input.lightLevel()<100){
|
||||||
|
led.setBrightness(255);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If the screen [brightness](/reference/led/brightness) is `< 100`, this code sets the brightness to `255`:
|
If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`:
|
||||||
|
|
||||||
### Lessons
|
### Lessons
|
||||||
|
|
||||||
|
@ -1,26 +1,8 @@
|
|||||||
# Loops
|
# Loops
|
||||||
|
|
||||||
Repeat code.
|
```cards
|
||||||
|
|
||||||
|
|
||||||
[for](/reference/loops/for)
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
for(let i = 0;i<5;i++) {}
|
for(let i = 0;i<5;i++) {}
|
||||||
```
|
for(let i = 1;i<5;i++) {}
|
||||||
|
|
||||||
[repeat](/reference/loops/repeat)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
[while](/reference/loops/while)
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
while(true) {}
|
while(true) {}
|
||||||
```
|
|
||||||
|
|
||||||
[forever](/reference/basic/forever)
|
|
||||||
|
|
||||||
```blocks
|
|
||||||
basic.forever(() => {})
|
basic.forever(() => {})
|
||||||
```
|
```
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
# For
|
# For
|
||||||
|
|
||||||
Repeat code a preset number of times.
|
|
||||||
|
|
||||||
### @parent blocks/language
|
### @parent blocks/language
|
||||||
|
|
||||||
|
|
||||||
Repeat code a fixed number of times.
|
Repeat code a fixed number of times.
|
||||||
|
|
||||||
### Block Editor
|
```blocks
|
||||||
|
for(let i = 0; i < 5; ++i) {
|
||||||

|
}
|
||||||
|
```
|
||||||
|
|
||||||
The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times:
|
The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times:
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
Repeat code a preset number of times.
|
Repeat code a preset number of times.
|
||||||
|
|
||||||
Repeat code a fixed number of times.
|
|
||||||
|
|
||||||
### Block Editor
|
### Block Editor
|
||||||
|
|
||||||

|

|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
# While
|
# While
|
||||||
|
|
||||||
Repeat code in a loop while a condition is true.
|
|
||||||
|
|
||||||
### @parent blocks/language
|
### @parent blocks/language
|
||||||
|
|
||||||
|
|
||||||
Repeat code while a [Boolean](/reference/types/boolean) `condition` is true.
|
Repeat code while a [Boolean](/reference/types/boolean) `condition` is true.
|
||||||
|
|
||||||
### ~hide
|
```blocks
|
||||||
|
while(true) {
|
||||||
|
}
|
||||||
```
|
```
|
||||||
let condition = false
|
|
||||||
```
|
|
||||||
|
|
||||||
### ~
|
|
||||||
|
|
||||||
### Block Editor
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
The while loop has a *condition* that evaluates to a [Boolean](/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`.
|
The while loop has a *condition* that evaluates to a [Boolean](/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`.
|
||||||
|
|
||||||
@ -27,11 +18,13 @@ The condition is tested before any code runs. Which means that if the condition
|
|||||||
|
|
||||||
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
|
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
|
||||||
|
|
||||||
// index is set to 4
|
```blocks
|
||||||
|
let index = 4;
|
||||||

|
while(index >= 0) {
|
||||||
|
led.plot(index, index);
|
||||||
// subtract 1 from `index` each time through loop
|
index--;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Lessons
|
### Lessons
|
||||||
|
|
||||||
|
@ -16,5 +16,5 @@ radio.receivedSignalStrength();
|
|||||||
radio.setGroup(0);
|
radio.setGroup(0);
|
||||||
radio.setTransmitPower(0);
|
radio.setTransmitPower(0);
|
||||||
radio.writeValueToSerial();
|
radio.writeValueToSerial();
|
||||||
radio.setTransmitSerialNumber(◊);
|
radio.setTransmitSerialNumber(true);
|
||||||
```
|
```
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
Reading and writing data over a serial connection.
|
Reading and writing data over a serial connection.
|
||||||
|
|
||||||
```cards
|
```cards
|
||||||
serial.writeValue(x, 0);
|
|
||||||
serial.writeLine("");
|
serial.writeLine("");
|
||||||
|
serial.writeNumber(0);
|
||||||
|
serial.writeValue(x, 0);
|
||||||
|
serial.writeString("");
|
||||||
|
serial.readLine();
|
||||||
```
|
```
|
||||||
|
@ -93,6 +93,9 @@
|
|||||||
"radio.setTransmitSerialNumber": "Set the radio to transmit the serial number in each message.",
|
"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",
|
"radio.writeValueToSerial": "Reads a value sent with `stream value` and writes it\nto the serial stream as JSON",
|
||||||
"serial": "Reading and writing data over a serial connection.",
|
"serial": "Reading and writing data over a serial connection.",
|
||||||
|
"serial.readLine": "Reads a line of text from the serial port.",
|
||||||
"serial.writeLine": "Prints a line of text to the serial",
|
"serial.writeLine": "Prints a line of text to the serial",
|
||||||
|
"serial.writeNumber": "Prints a numeric value to the serial",
|
||||||
|
"serial.writeString": "Sends a piece of text through Serial connection.",
|
||||||
"serial.writeValue": "Writes a ``name: value`` pair line to the serial."
|
"serial.writeValue": "Writes a ``name: value`` pair line to the serial."
|
||||||
}
|
}
|
@ -28,8 +28,8 @@ namespace serial {
|
|||||||
* Registers an event to be fired when one of the delimiter is matched
|
* Registers an event to be fired when one of the delimiter is matched
|
||||||
* @param delimiters the characters to match received characters against. eg:"\n"
|
* @param delimiters the characters to match received characters against. eg:"\n"
|
||||||
*/
|
*/
|
||||||
//% help=serial/on-data-received
|
// help=serial/on-data-received
|
||||||
//% weight=19
|
// weight=19
|
||||||
void onDataReceived(StringData* delimiters, Action body) {
|
void onDataReceived(StringData* delimiters, Action body) {
|
||||||
uBit.serial.eventOn(ManagedString(delimiters));
|
uBit.serial.eventOn(ManagedString(delimiters));
|
||||||
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
||||||
|
@ -39,10 +39,10 @@ namespace serial {
|
|||||||
/**
|
/**
|
||||||
* Registers an event to be fired when a line has been received
|
* Registers an event to be fired when a line has been received
|
||||||
*/
|
*/
|
||||||
//% help=serial/on-line-received
|
// help=serial/on-line-received
|
||||||
//% blockId=serial_on_line_received block="serial on line received"
|
// blockId=serial_on_line_received block="serial on line received"
|
||||||
//% weight=21 blockGap=8
|
// weight=21 blockGap=8
|
||||||
export function onLineReceived(body: Action): void {
|
export function onLineReceived(body: Action): void {
|
||||||
serial.onDataReceived("\n", body);
|
// serial.onDataReceived("\n", body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
libs/microbit/shims.d.ts
vendored
8
libs/microbit/shims.d.ts
vendored
@ -575,14 +575,6 @@ declare namespace serial {
|
|||||||
//% weight=87
|
//% weight=87
|
||||||
//% blockId=serial_writestring block="serial write string %text" shim=serial::writeString
|
//% blockId=serial_writestring block="serial write string %text" shim=serial::writeString
|
||||||
function writeString(text: string): void;
|
function writeString(text: string): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers an event to be fired when one of the delimiter is matched
|
|
||||||
* @param delimiters the characters to match received characters against. eg:"\n"
|
|
||||||
*/
|
|
||||||
//% help=serial/on-data-received
|
|
||||||
//% weight=19 shim=serial::onDataReceived
|
|
||||||
function onDataReceived(delimiters: string, body: () => void): void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.124",
|
"version": "0.2.125",
|
||||||
"description": "BBC micro:bit target for PXT",
|
"description": "BBC micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.2.130"
|
"pxt-core": "0.2.131"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,6 +430,10 @@ namespace pxsim.serial {
|
|||||||
return board().readSerial();
|
return board().readSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readLine(): string {
|
||||||
|
return board().readSerial();
|
||||||
|
}
|
||||||
|
|
||||||
export function onDataReceived(delimiters: string, handler: RefAction) {
|
export function onDataReceived(delimiters: string, handler: RefAction) {
|
||||||
let b = board();
|
let b = board();
|
||||||
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
||||||
|
Reference in New Issue
Block a user