Migrate docs from the other repo
This commit is contained in:
31
docs/reference/basic/clear-screen.md
Normal file
31
docs/reference/basic/clear-screen.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Clear Screen
|
||||
|
||||
Turn off all the LED lights on the [LED screen](/microbit/device/screen).
|
||||
|
||||
```sig
|
||||
basic.clearScreen()
|
||||
```
|
||||
|
||||
### Example: vanishing heart
|
||||
|
||||
The following code displays a heart on the screen and then turns off all the LED lights using `clear screen`:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.clearScreen()
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[blink](/microbit/lessons/blink), [flashing heart](/microbit/lessons/flashing-heart), [screen wipe](/microbit/lessons/screen-wipe)
|
||||
|
||||
### See also
|
||||
|
||||
[set brightness](/microbit/reference/led/set-brightness), [unplot](/microbit/reference/led/unplot), [plot](/microbit/reference/led/plot), [Image](/microbit/reference/image/image), [clear](/microbit/reference/basic/clear-screen)
|
||||
|
65
docs/reference/basic/forever.md
Normal file
65
docs/reference/basic/forever.md
Normal file
@ -0,0 +1,65 @@
|
||||
# Forever
|
||||
|
||||
Repeat code [in the background](/microbit/reference/control/in-background) forever.
|
||||
|
||||
```sig
|
||||
basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
### Example: compass
|
||||
|
||||
The following example constantly checks the [compass heading](/microbit/reference/input/compass-heading) and updates the screen with the direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let heading = input.compassHeading()
|
||||
if (heading < 45) {
|
||||
basic.showString("N", 100)
|
||||
} else if (heading < 135) {
|
||||
basic.showString("E", 100)
|
||||
}
|
||||
else if (heading < 225) {
|
||||
basic.showString("S", 100)
|
||||
}
|
||||
else {
|
||||
basic.showString("W", 100)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Example: counter
|
||||
|
||||
The following example continually shows the current value of a global variable:
|
||||
|
||||
```blocks
|
||||
let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num, 150)
|
||||
})
|
||||
input.onButtonPressed("A", () => {
|
||||
num = num + 1
|
||||
})
|
||||
```
|
||||
|
||||
### Contention for the LED display
|
||||
|
||||
If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showNumber(6789, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showNumber(2, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[blink](/microbit/lessons/blink), [bounce-image](/microbit/lessons/bounce-image), [snowflake-fall](/microbit/lessons/snowflake-fall), [flashing-heart](/microbit/lessons/flashing-heart)
|
||||
|
||||
### See also
|
||||
|
||||
[while](/microbit/js/while), [on button pressed](/microbit/reference/input/on-button-pressed), [in background](/microbit/reference/control/in-background)
|
||||
|
31
docs/reference/basic/pause.md
Normal file
31
docs/reference/basic/pause.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Pause
|
||||
|
||||
Pause program execution for the specified number of milliseconds. This function is helpful when you need to slow down your program's execution.
|
||||
|
||||
```sig
|
||||
basic.pause(400)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``ms`` - the number of milliseconds that you want to pause (100 = 1/10 second, 1000 milliseconds = 1 second)
|
||||
|
||||
### Example: diagonal line
|
||||
|
||||
The following example code turns on LED `0, 0` thru `4, 4`, pausing 500 milliseconds after each LED. Without `pause`, the code would run so fast that you wouldn't see each individual LED turning on.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
led.plot(i, i)
|
||||
basic.pause(500)
|
||||
}
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[blink](/microbit/lessons/blink), [lucky 7](/microbit/lessons/lucky-7), [smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart)
|
||||
|
||||
### See also
|
||||
|
||||
[while](/microbit/js/while), [running time](/microbit/reference/input/running-time), [for](/microbit/reference/loops/for)
|
||||
|
61
docs/reference/basic/show-animation.md
Normal file
61
docs/reference/basic/show-animation.md
Normal file
@ -0,0 +1,61 @@
|
||||
# Show Animation
|
||||
|
||||
Show a series of image frames on the [LED screen](/microbit/device/screen), pausing the specified time after each frame.
|
||||
|
||||
```sig
|
||||
basic.showAnimation(`
|
||||
. . # . . . # # # . . # # # .
|
||||
. # # . . . . . # . . . . # .
|
||||
. . # . . . . # . . . # # # .
|
||||
. . # . . . # . . . . . . # .
|
||||
. . # . . . # # # . . # # # .
|
||||
`)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `leds` - [String](/microbit/reference/types/string); a series of LED on/off states
|
||||
* `interval` - [Number](/microbit/reference/types/number); the number of milliseconds to pause after each image frame
|
||||
|
||||
### Show a series of image frames
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. . # . . . # # # . . # # # .
|
||||
. # # . . . . . # . . . . # .
|
||||
. . # . . . . # . . . # # # .
|
||||
. . # . . . # . . . . . . # .
|
||||
. . # . . . # # # . . # # # .
|
||||
`)
|
||||
```
|
||||
|
||||
### ~hint
|
||||
|
||||
If the series of images appear too fast, increase the value of the *interval* parameter.
|
||||
|
||||
### ~
|
||||
|
||||
### Example: animating frames
|
||||
|
||||
The following example creates an image with six frames and then shows each frame o the screen, pausing 500 milliseconds after each frame:
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
|
||||
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
|
||||
. # . # . . . # . . . # . # . . . # . . . # . # . . . # . .
|
||||
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
|
||||
. . . . . . . . . # . . . . . # . . . . . . . . . . . . . #
|
||||
`, 500)
|
||||
```
|
||||
|
||||
### ~hint
|
||||
|
||||
Use [forever](/microbit/reference/basic/forever) to continually repeat an animation
|
||||
|
||||
### ~
|
||||
|
||||
### Lessons
|
||||
|
||||
[smiley](/microbit/lessons/smiley), [bounce image](/microbit/lessons/bounce-image), [snowflake fall](/microbit/lessons/snowflake-fall), [rotation animation](/microbit/lessons/rotation-animation)
|
||||
|
45
docs/reference/basic/show-leds.md
Normal file
45
docs/reference/basic/show-leds.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Show LEDs
|
||||
|
||||
Display an image on the BBC micro:bit's [LED screen](/microbit/device/screen).
|
||||
|
||||
```sig
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``leds`` - a series of LED on/off states that form an image (see steps below)
|
||||
* (optional) ``ms`` - [Number](/microbit/reference/types/number) - time to wait after displaying image. In blocks, ``ms`` is 400 by default.
|
||||
|
||||
### Example - Block Editor
|
||||
|
||||
1. Open the `basic` category and select the `show leds` blocks.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # . # .
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
In JavaScript, the led off is represented by a `.` and the led on by a `#` character.
|
||||
|
||||
### Lessons
|
||||
|
||||
[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo)
|
||||
|
||||
### See also
|
||||
|
||||
[plot leds](/microbit/reference/led/plot-leds), [show animation](/microbit/reference/led/show-animation)
|
||||
|
52
docs/reference/basic/show-number.md
Normal file
52
docs/reference/basic/show-number.md
Normal file
@ -0,0 +1,52 @@
|
||||
# Show Number
|
||||
|
||||
Show a number on the [LED screen](/microbit/device/screen), one digit at a time (scrolling from left to right)
|
||||
|
||||
~~~~sig
|
||||
basic.showNumber(2, 150)
|
||||
~~~~
|
||||
|
||||
### Parameters
|
||||
|
||||
* value - a [Number](/microbit/reference/types/number)
|
||||
* (optional) interval (ms) - [Number](/microbit/reference/types/number); the time (in milliseconds) before scrolling by one LED; the larger the number, the slower the scroll
|
||||
|
||||
### ~
|
||||
|
||||
To display the number 10:
|
||||
|
||||
~~~~blocks
|
||||
basic.showNumber(10)
|
||||
~~~~
|
||||
|
||||
To display the number stored in the `x` variable:
|
||||
|
||||
~~~~blocks
|
||||
let x = 1
|
||||
basic.showNumber(x)
|
||||
~~~~
|
||||
|
||||
### Example: count to 5
|
||||
|
||||
This example uses a [for](/microbit/reference/loops/for) loop to show numbers ``1`` through ``5`` on the screen:
|
||||
|
||||
~~~~blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
basic.showNumber(i + 1)
|
||||
basic.pause(200)
|
||||
}
|
||||
~~~~
|
||||
|
||||
### Other show functions
|
||||
|
||||
* use [show string](/microbit/reference/basic/show-string) to show a string on the screen
|
||||
* use [show animation](/microbit/reference/basic/show-animation) to show a series of images on the screen
|
||||
|
||||
### Lessons
|
||||
|
||||
* [lucky 7](/microbit/lessons/lucky-7)
|
||||
|
||||
### See also
|
||||
|
||||
[show string](/microbit/reference/basic/show-string), [show animation](/microbit/reference/basic/show-animation), [Number](/microbit/reference/types/number), [math library](/microbit/js/math)
|
||||
|
41
docs/reference/basic/show-string.md
Normal file
41
docs/reference/basic/show-string.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Show String
|
||||
|
||||
Show a string on the [LED screen](/microbit/device/screen) one character at a time (scrolling from left to right).
|
||||
|
||||
```sig
|
||||
basic.showString("Hello!")
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `text` - a [String](/microbit/reference/types/string)
|
||||
* (optional) `ms` - [Number](/microbit/reference/types/number); the time (in milliseconds) before scrolling left by one LED; the larger the number, the slower the scroll
|
||||
|
||||
### Examples:
|
||||
|
||||
To display Hello:
|
||||
|
||||
```blocks
|
||||
basic.showString("Hello")
|
||||
```
|
||||
|
||||
To display the content of a string variable:
|
||||
|
||||
```blocks
|
||||
let s = "Hi"
|
||||
basic.showString(s)
|
||||
```
|
||||
|
||||
### Other show functions
|
||||
|
||||
* use [show number](/microbit/reference/basic/show-number) to show a number on the screen
|
||||
* use [show animation](/microbit/reference/basic/show-animation) to show a series of images on the screen
|
||||
|
||||
### Lessons
|
||||
|
||||
[answering machine](/microbit/lessons/answering-machine), [rock paper scissors](/microbit/lessons/rock-paper-scissors), [love meter](/microbit/lessons/love-meter), [digital pet](/microbit/lessons/digital-pet)
|
||||
|
||||
### See also
|
||||
|
||||
[String](/microbit/reference/types/string), [string functions](/microbit/reference/types/string-functions), [show number](/microbit/reference/basic/show-number), [show animation](/microbit/reference/basic/show-animation)
|
||||
|
Reference in New Issue
Block a user