various docs updates

This commit is contained in:
Peli de Halleux 2016-05-19 13:56:24 -07:00
parent 9a36a2fc05
commit c65bdb34af
10 changed files with 41 additions and 90 deletions

View File

@ -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(`
. . . . . . . . . .

View File

@ -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;
``` ```

View File

@ -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) {
![](/static/mb/hourofcode-0.png) }
```
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
![](/static/mb/blocks/game-library/pic0.png) ```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

View File

@ -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)
![](/static/mb/blocks/contents-0.png)
[while](/reference/loops/while)
```blocks
while(true) {} while(true) {}
```
[forever](/reference/basic/forever)
```blocks
basic.forever(() => {}) basic.forever(() => {})
``` ```

View File

@ -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) {
![](/static/mb/events-0.png) }
```
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:

View File

@ -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
![](/static/mb/blocks/contents-0.png) ![](/static/mb/blocks/contents-0.png)

View File

@ -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
![](/static/mb/string-0.png)
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;
![](/static/mb/blocks/var-10.png) while(index >= 0) {
led.plot(index, index);
// subtract 1 from `index` each time through loop index--;
}
```
### Lessons ### Lessons

View File

@ -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);
``` ```

View File

@ -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();
``` ```

View File

@ -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."
} }