Rest of Basic in simple English. Reconsider some code samples?
This commit is contained in:
parent
9c96591edd
commit
21361708ec
@ -1,6 +1,7 @@
|
|||||||
# Forever
|
# Forever
|
||||||
|
|
||||||
Repeat code [in the background](/reference/control/in-background) forever.
|
Keep running part of a program
|
||||||
|
[in the background](/reference/control/in-background).
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
@ -9,7 +10,9 @@ basic.forever(() => {
|
|||||||
|
|
||||||
### Example: compass
|
### Example: compass
|
||||||
|
|
||||||
The following example constantly checks the [compass heading](/reference/input/compass-heading) and updates the screen with the direction.
|
The following example constantly checks the
|
||||||
|
[compass heading](/reference/input/compass-heading)
|
||||||
|
and updates the screen with the direction.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
@ -30,7 +33,9 @@ basic.forever(() => {
|
|||||||
|
|
||||||
### Example: counter
|
### Example: counter
|
||||||
|
|
||||||
The following example continually shows the current value of a global variable:
|
The following example keeps showing the [number](/reference/types/number) stored in a global variable.
|
||||||
|
When you press button `A`, the number gets bigger.
|
||||||
|
You can use a program like this to count things with your BBC micro:bit.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let num = 0
|
let num = 0
|
||||||
@ -42,9 +47,12 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Contention for the LED display
|
### Competing for the LED screen
|
||||||
|
|
||||||
If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example:
|
If different parts of a program are each trying
|
||||||
|
to show something on the LED screen at the same time,
|
||||||
|
you may get unexpected results.
|
||||||
|
Try this on your micro:bit:
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# Pause
|
# Pause
|
||||||
|
|
||||||
Pause program execution for the specified number of milliseconds. This function is helpful when you need to slow down your program's execution.
|
Pause the program for the number of milliseconds you say.
|
||||||
|
You can use this function to slow your program down.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
basic.pause(400)
|
basic.pause(400)
|
||||||
@ -8,11 +9,13 @@ basic.pause(400)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* ``ms`` - the number of milliseconds that you want to pause (100 = 1/10 second, 1000 milliseconds = 1 second)
|
* ``ms`` is the number of milliseconds that you want to pause (100 milliseconds = 1/10 second, and 1000 milliseconds = 1 second).
|
||||||
|
|
||||||
### Example: diagonal line
|
### Example: diagonal line
|
||||||
|
|
||||||
The following example code turns on LED `0, 0` thru `4, 4`, pausing 500 milliseconds after each LED. Without `pause`, the code would run so fast that you wouldn't see each individual LED turning on.
|
This example draws a diagonal line by turning on LED `0, 0` (top left) through LED `4, 4` (bottom right).
|
||||||
|
The program pauses 500 milliseconds after turning on each LED.
|
||||||
|
Without `pause`, the program would run so fast that you would not have time to see each LED turning on.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user