Compare commits

...

39 Commits

Author SHA1 Message Date
3f8fa4b05b 0.2.130 2016-05-25 10:53:55 -07:00
53ab8651bd Bump pxt-core to 0.2.139 2016-05-25 10:53:52 -07:00
87300be648 updated starter template 2016-05-24 22:18:33 -07:00
d0a7df7f36 0.2.129 2016-05-24 21:57:47 -07:00
1c8fa5eab6 move pins->map up in block list 2016-05-24 21:39:57 -07:00
d8c2d697b1 Merge pull request #75 from gbaman/master
Add few more radio documentation pages
2016-05-24 21:21:00 -07:00
2ede815535 Add write-value-to-serial documentation 2016-05-25 02:58:27 +01:00
a67f16a860 Deleted redundant paragraph. 2016-05-24 18:27:14 -07:00
819ab9aa9a Add receive-string documentation page 2016-05-25 02:23:33 +01:00
318ffde27f Add send-string documentation page 2016-05-25 01:53:13 +01:00
525e59ae4f Heavy rewrite; added Fahrenheit example too for US. 2016-05-24 17:51:10 -07:00
ab087b4afa Add set-transmit-power documentation page 2016-05-25 01:40:01 +01:00
3b8ae69a6c Rewrite of text and examples. 2016-05-24 15:36:04 -07:00
8de6605112 0.2.128 2016-05-24 14:32:27 -07:00
daea493dcb Bump pxt-core to 0.2.138 2016-05-24 14:32:11 -07:00
b290692334 using pxt constant to find binary .hex 2016-05-24 14:06:25 -07:00
f25f295d0c 0.2.127 2016-05-24 13:03:06 -07:00
5fd691ef92 Bump pxt-core to 0.2.137 2016-05-24 13:03:04 -07:00
67c8753315 Updating loop docs 2016-05-24 12:30:31 -07:00
9d405afde0 0.2.126 2016-05-24 11:41:37 -07:00
b05c8ebd56 Bump pxt-core to 0.2.136 2016-05-24 11:41:35 -07:00
b69156a12e adding target compile service configuration 2016-05-24 09:46:33 -07:00
961e2cb6e9 Simple language rewrite. Needs new code example; legacy one broken. 2016-05-23 18:02:40 -07:00
924d31a211 Simple language for short topic. 2016-05-23 17:21:36 -07:00
8721b54679 Pretty thoroughly rewritten in simple language. 2016-05-23 16:21:08 -07:00
e99292d008 Minor clarification 2016-05-23 14:46:11 -07:00
cc1ed10efb pics for the 10 activities 2016-05-23 17:39:44 -04:00
b48c11d380 Simpler language; added another (simpler) example. 2016-05-23 13:41:01 -07:00
3f1602f2c0 Simpler language, more interesting example (running time was always 0). 2016-05-23 12:45:14 -07:00
324fd45fb6 Rewriting play-tone for correctness & clarity. 2016-05-23 11:50:08 -07:00
d1a3892eab Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-21 08:25:16 -07:00
28d28eb67f Rewrite text, code sample. 2016-05-20 18:33:31 -07:00
a67164d5e6 Making another topic easier to understand. 2016-05-20 16:05:45 -07:00
86b35ae88d Absolutely necessary tiny tweak. 2016-05-20 15:36:37 -07:00
919c8fdfca Rewrite in simple English, debug the examples. 2016-05-20 15:33:15 -07:00
4abdb28a59 More simple English docs. 2016-05-20 13:24:27 -07:00
21361708ec Rest of Basic in simple English. Reconsider some code samples? 2016-05-20 13:09:18 -07:00
4e56342e52 updated docs 2016-05-20 05:40:54 -07:00
7273354944 support for 3g/6g gestures 2016-05-20 05:39:44 -07:00
38 changed files with 401 additions and 109 deletions

View File

@ -1,8 +1,8 @@
/// <reference path="../node_modules/pxt-core/built/pxt.d.ts"/>
import * as fs from 'fs';
import * as path from 'path';
import * as child_process from 'child_process';
import * as fs from "fs";
import * as path from "path";
import * as child_process from "child_process";
let writeFileAsync: any = Promise.promisify(fs.writeFile)
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
@ -13,10 +13,10 @@ export function deployCoreAsync(res: ts.pxt.CompileResult) {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to")
} else {
console.log("copy microbit.hex to " + drives.join(", "))
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
}
return Promise.map(drives, d =>
writeFileAsync(d + "microbit.hex", res.outfiles["microbit.hex"])
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
.then(() => {
console.log("wrote hex file to " + d)
}))

View File

@ -8,7 +8,7 @@ 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`:
The following code shows a heart on the screen and then turns off all the LED lights using `clear screen`:
```blocks
basic.showLeds(`

View File

@ -1,6 +1,7 @@
# 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
basic.forever(() => {
@ -9,7 +10,9 @@ basic.forever(() => {
### 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
basic.forever(() => {
@ -30,7 +33,9 @@ basic.forever(() => {
### 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
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
basic.forever(() => {

View File

@ -1,6 +1,7 @@
# 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
basic.pause(400)
@ -8,11 +9,13 @@ basic.pause(400)
### 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
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
for (let i = 0; i < 5; i++) {

View File

@ -1,6 +1,6 @@
# Button Is Pressed
Get the state of an input button. The micro:bit has two input buttons: A and B.
Check whether a button is pressed right now. The micro:bit has two buttons: button `A` and button `B`.
```sig
input.buttonIsPressed(Button.A);
@ -8,24 +8,26 @@ input.buttonIsPressed(Button.A);
### Parameters
* name - [String](/reference/types/string); input button "A", "B", or "A+B" (both input buttons)
* ``name`` is a [String](/reference/types/string). You should store `A` in it to check the left button, `B` to check the right button, or `A+B` to check both at the same time.
### Returns
* [Boolean](/reference/types/boolean) - `true` if pressed, `false` if not pressed
* [Boolean](/reference/types/boolean) that is `true` if the button you are checking is pressed, `false` if it is not pressed.
### Example
The following code uses an [if](/reference/logic/if) statement to run code, depending on whether or not the A button is pressed:
This program uses an [if](/reference/logic/if) to run
one part of the program if the `A` button is pressed, and
another part if it is not pressed.
```blocks
basic.forever(() => {
let pressed = input.buttonIsPressed(Button.A)
if (pressed) {
// this code runs if the A button is pressed
// this part runs if the A button is pressed
basic.showNumber(1, 150)
} else {
// this code runs if the A button is *not* pressed
// this part runs if the A button is *not* pressed
basic.showNumber(0, 150)
}
})

View File

@ -1,8 +1,14 @@
# Light Level
Gets the light level from ``0`` (dark) to ``255`` (bright). The light is measured by using various LEDs from the screen.
Find the light level (how bright or dark it is) where you are.
The light level ``0`` means darkness and ``255`` means bright light.
The BBC micro:bit measures the light around it by using some of the
LEDs on the [LED screen](/device/screen).
This function will return ``0`` on the first call to this method, a light reading will be available after the display has activated the light sensor for the first time.
The first time you use it, this function will say ``0``.
After that, it will say the real light level.
This is because the light sensor (the part that can find the light level)
has to be turned on first.
```sig
input.lightLevel();
@ -10,11 +16,26 @@ input.lightLevel();
### Returns
* [Number](/reference/types/number) - light level from ``0`` (dark) to ``255`` (bright).
* a [Number](/reference/types/number) that means a light level from ``0`` (dark) to ``255`` (bright).
### Example: show light level
When you press button `B` on the microbit, this
program shows the light level
on the [LED screen](/device/screen).
```blocks
input.onButtonPressed(Button.B, () => {
let level = input.lightLevel()
basic.showNumber(level)
})
```
### Example: chart light level
Use `plot bar chart` to visual the influence of various light source on the light level.
This program shows the light level with a [bar chart](/reference/led/plot-bar-graph) on the micro:bit screen.
If you carry the micro:bit around to different places with different light levels,
the bar chart will change.
```blocks
basic.forever(() => {

View File

@ -1,6 +1,9 @@
# On Button Pressed
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed).
This handler works when button `A` or `B` is pressed, or `A` and `B` together.
When you are using this function in a web browser, click the buttons on the screen instead of the ones
on the BBC micro:bit.
```sig
input.onButtonPressed(Button.A, () => {})
@ -8,7 +11,8 @@ input.onButtonPressed(Button.A, () => {})
### Example: count button clicks
This example counts how many times the left or right input button is pressed. Each time a button is pressed, the global count variable is increased by 1 and displayed on the screen.
This example counts how many times you press the `A` button.
Each time you press the button, the [LED screen](/device/screen) shows the `count` variable getting bigger.
```blocks
let count = 0
@ -19,22 +23,29 @@ input.onButtonPressed(Button.A, () => {
})
```
### Example: roll a dice
### Example: roll dice
This example generates a random number when you press the B input button, and then displays a random die image:
This example shows a number from 1 to 6 when you press the `B` button.
```blocks
input.onButtonPressed(Button.B, () => {
let dice = Math.random(6)
let dice = Math.random(6) + 1
basic.showNumber(dice)
})
```
### ~hint
This program adds a `1` to `random(6)` so the numbers on the dice will come out right.
Otherwise, sometimes they would show a `0`.
### ~
### Lessons
[smiley](/lessons/smiley), [answering machine](/lessons/answering-machine), [screen wipe](/lessons/screen-wipe), [rotation animation](/lessons/rotation-animation)
### See also
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever)
[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/reference/math/math)

View File

@ -1,6 +1,6 @@
# Running Time
Get the number of milliseconds elapsed since the script began. 1,000 milliseconds = 1 second.
Find how long it has been since the program started.
```sig
input.runningTime();
@ -8,15 +8,20 @@ input.runningTime();
### Returns
* [Number](/reference/types/number)
* the [Number](/reference/types/number) of milliseconds since the program started.
(One second is 1000 milliseconds.)
### Example: elapsed time
This code gets the elapsed time since the start of the program execution and displays it on the screen.
When you press button `B` on the microbit, this
program finds the number of milliseconds since the program started
and shows it on the [LED screen](/device/screen).
```blocks
let now = input.runningTime()
basic.showNumber(now)
input.onButtonPressed(Button.B, () => {
let now = input.runningTime()
basic.showNumber(now)
})
```
### Lessons

View File

@ -1,6 +1,7 @@
# Temperature
Get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit.
Find the temperature where you are. The temperature is measured in Celsius (metric).
The micro:bit can find the temperature nearby by checking how hot its computer chips are.
```sig
input.temperature();
@ -8,24 +9,48 @@ input.temperature();
### Returns
* [Number](/reference/types/number) - temperature in degree Celsius °C.
* a [Number](/reference/types/number) that means the Celsius temperature.
### How does it work?
The BBC micro:bit does not have a dedicated temperature sensor. Instead, the temperature provided is actually the temperature of the silicon die on the main CPU. As the processor generally runs cold though (it is a high efficiency ARM core), the temperature is a good approximation of the ambient temperature... you might warm up if you give the processor a lot of work to do though, and don't [sleep](/reference/basic/pause)!
The temperature sensor has a high precision, but isn't trimmed for accuracy. In other words, it can sense changes in temperature very well, but there may be (and probably is) base line offset. i.e. it might return 20 degrees when it's actually 17, but it would return 21 when it is 18 etc.
The BBC micro:bit checks how hot its CPU (main computer chip) is.
Because the micro:bit does not usually get very hot, the temperature of the CPU
is usually close to the temperature of wherever you are.
The micro:bit might warm up a little if you make it work hard, though!
### Example: micro:bit thermometer
The following example uses the `temperature` and the `show number` to display the room temperature.
The following example uses `temperature` and `show number` to show the temperature of the room.
```sig
```blocks
basic.forever(() => {
let temp = input.temperature()
basic.showNumber(temp)
})
```
### Example: Fahrenheit thermometer
This program measures the temperature using Fahrenheit degrees.
Fahrenheit is a way of measuring temperature that is commonly used in the United States.
To make a Celsius temperature into a Fahrenheit one, multiply the Celsius temperature by
1.8 and add 32.
```blocks
basic.forever(() => {
let c = input.temperature()
let f = (c * 1.8) + 32
basic.showNumber(f)
})
```
### ~hint
Try comparing the temperature your micro:bit shows to a real thermometer in the same place.
You might be able to figure out how much to subtract from the number the micro:bit
shows to get the real temperature. Then you can change your program so the micro:bit is a
better thermometer.
### ~
### Lessons

View File

@ -1,6 +1,6 @@
# Brightness
Set the brightness of the [LED screen](/device/screen).
Find how bright the [LED screen](/device/screen) is.
```sig
led.brightness();
@ -8,11 +8,11 @@ led.brightness();
### Returns
* [Number](/reference/types/number) - returns the LCD screen brightness as a number from 0 to 255. A return value of 255 means the screen brightness is at 100% and 127 is about 50% brightness.
* a [Number](/reference/types/number) that means how bright the screen is, from `0` (darkest) to `255` (brightest). For example, the number `127` means the screen is halfway bright.
### Example: maximum brightness
### Example: highest brightness
If the screen brightness is < 100%, the following code sets the brightness to 100% (255):
This program makes the screen completely bright if it is not that way already:
```blocks
if (led.brightness() < 255) {

View File

@ -1,6 +1,7 @@
# Plot Bar Graph
Displays a vertical bar graph based on the value and high value.
Displays a bar graph of the numbers you say.
A bar graph is a kind of chart that shows numbers as lines with different lengths.
```sig
led.plotBarGraph(2, 20);
@ -8,10 +9,18 @@ led.plotBarGraph(2, 20);
### Parameters
* value: [Number](/reference/types/number) , high : [Number](/reference/types/number) displays a vertical bar graph based on the value and high value
* `value` is a [Number](/reference/types/number) that means what you are measuring or trying to show. For example, if you are measuring the temperature of ice with the BBC micro:bit, `value` might be 0 because the temperature might be 0 degrees centigrade.
* `high` is a [Number](/reference/types/number) that means the highest possible number that the `value` parameter can be. This number is also the tallest that the lines in the bar chart can be.
### Example: chart acceleration
This program shows a bar graph of the [acceleration](/reference/input/acceleration)
in the `x` direction of the micro:bit.
The micro:bit's `x` direction is from left to right (or right to left).
The more you speed up moving the micro:bit in this direction,
the taller the lines in the bar graph will be,
until they are as tall as the parameter `high` says they can be.
```blocks
basic.forever(() => {
let a = input.acceleration(Dimension.X);

View File

@ -2,17 +2,15 @@
### @parent blocks/language
Repeat code a fixed number of times.
Run part of the program the number of times you say.
### Example: Count to 4
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
```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:
```
for (let k = 0; k < 4; k++) {
basic.showNumber(i)
}
```
@ -22,5 +20,5 @@ for (let k = 0; k < 4; k++) {
### See also
[while](/reference/loops/while), [if](/reference/logic/if)
[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,19 +1,16 @@
# Repeat
Repeat code a preset number of times.
Run part of the program the number of times you say.
### Block Editor
![](/static/mb/blocks/contents-0.png)
### Touch Develop
### Lessons
Touch Develop has no `repeat` loop. Instead you can used a for loop
[looper](/lessons/looper)
```
for (let i = 0; i < 5; i++) {
}
```
### See also
The loop above will repeat five (5) times.
[for](/reference/loops/for), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,10 +1,10 @@
# Play Tone
Plays a music tone through pin ``P0`` for the given duration.
Play a musical tone through pin ``P0`` of the micro:bit for as long as you say.
## Simulator
Simulation of this function is available in many, but not all browsers.
This function only works on the micro:bit and in some browsers.
```sig
music.playTone(440, 120)
@ -12,11 +12,14 @@ music.playTone(440, 120)
### Parameters
* `frequency` : [Number](/reference/types/number) - the frequency of the note (in Herz)
* `ms`: [Number](/reference/types/number) - the duration of the note (milliseconds)
* `Hz` is the [Number](/reference/types/number) of Hertz (the frequency, how high or low the tone is).
* `ms` is the [Number](/reference/types/number) of milliseconds that the tone lasts.
## Example
This example stores the musical note C in the variable `freq`.
Next, it plays that note for 1000 milliseconds (one second).
```blocks
let freq = music.noteFrequency(Note.C)
music.playTone(freq, 1000)

View File

@ -1,16 +1,16 @@
# Tempo
Returns the tempo in beats per minute.
Finds the tempo (speed of a piece of music).
```sig
music.tempo()
```
### Parameters
### Returns
* Returns : [Number](/reference/types/number) - returns the tempo in beats per minute
* a [Number](/reference/types/number) that means the bpm (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
### See also
[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone) , [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)
[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone), [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)

View File

@ -0,0 +1,67 @@
# Receive String
Reads the next radio packet if any and returns the first string.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.receiveString()
```
### Return value
* the first [string](/reference/types/string) of the packet if any. ```""``` otherwise.
### Examples
Read the string broadcasted by other micro:bits and display it.
```blocks
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
});
```
A simple program to send whether you are happy, or sad over ```radio```, using the A or B button to select an emotion.
```blocks
let data: string = "";
input.onButtonPressed(Button.A, () => {
radio.sendString("H");
});
input.onButtonPressed(Button.B, () => {
radio.sendString("S");
});
radio.onDataReceived(() => {
data = radio.receiveString();
if ("H" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`);
} else if ("S" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`);
} else {
basic.showString("?");
}
});
```
### See also
[send string](/reference/input/send-string), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,33 @@
# Send String
Broadcasts a string data packet to other micro:bits connected via ``radio``.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.sendString("Hello world!")
```
### Parameters
* msg - a string to be transmitted.
### Examples
Broadcasts the provided string to other micro:bits.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendString("Mr. Watson, come here, I want to see you.")
})
```
### See also
[receive string](/reference/radio/receive-string), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,38 @@
# Set Transmit Power
Sets the transmitter power for ``radio`` communications.
The power can be set to a value between 0 (-30dbm) and 7 (+4dbm).
## Range
At power level 7, in an open area without significant interference (coming from WiFi networks or other devices operating on the 2.4 GHz range), you can get a **range of over 70m**.
Indoors (or with additional interference), range will be significantly reduced.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.setTransmitPower(1)
```
### Parameters
* ``power`` -- a [number](/reference/types/number) between ``0`` and ``7``.
### Example
Sets the transmitter power to full power at 7.
```blocks
radio.setTransmitPower(7)
```
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,45 @@
# Write Value To Serial
Writes the full data received data via ``radio`` to serial in JSON format.
**Note** - This method only works for [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value). It does not work for [send string](/reference/radio/send-string) (although a string can be sent with [send value](/reference/radio/send-value)).
## Data received format
The format for received data printed to serial is as follows
- [send number](/reference/radio/send-number) - ```{v:ValueSent,t:MicrobitTimeAlive,s:Unused}```
- [send value](/reference/radio/send-number) - ```{v:Value,t:MicrobitTimeAlive,s:Unused,n:"Name"}```
- [send string](/reference/radio/send-string) - ```{}``` (currently unavailable)
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.writeValueToSerial()
```
### Parameters
* None
### Examples
When ```radio``` data is received (after pressing A button on 2nd micro:bit), output temperature data to serial.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(input.temperature());
});
radio.onDataReceived(() => {
radio.writeValueToSerial();
});
```
Example output to serial when A button pressed:
```{v:27,t:323,s:0}```
### See also
[send number](/reference/radio/send-number), [send value](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -1,34 +1,34 @@
# Assignment Operator
Set the value for local and global variables.
Use an equals sign to make a [variable](/reference/variables/var) store the [number](/reference/types/number)
or [string](/reference/types/string) you say.
### @parent blocks/operators
When you use the equals sign to store something in a variable, the equals sign is called
an *assignment operator*, and what you store is called a *value*.
Set or change the value of a variable
### Storing numbers in variables
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
````blocks
let item = 0
let item = 5
basic.showNumber(item)
````
Use the assignment operator to set or change the value of a [variable](/reference/variables/var).
### Storing strings in variables
### Declare a variable
Declare a new *local* variable using the [variable](/reference/variables/var) statement and the assignment operator. Like this:
This program makes the variable `name` equal `Joe` and then shows it on the [LED screen](/device/screen).
````blocks
let num1 = 42;
let name = "Joe";
let name = "Joe"
basic.showString(name);
````
The variable's name is on the left of the assignment operator and the variable's value is on the right:
````blocks
let num1 = 42
````
### Notes
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
You can use the assignment operator with variables of
every [type](/reference/types). A *type* is which kind of thing
a variable can store, like a number or string.
### Lessons

BIN
docs/static/mb/activities/a1-display.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a10-watch.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
docs/static/mb/activities/a2-buttons.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a3-pins.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/static/mb/activities/a4-motion.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
docs/static/mb/activities/a5-compass.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/static/mb/activities/a6-music.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
docs/static/mb/activities/a8-network.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
docs/static/mb/activities/a9-radio.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -105,6 +105,16 @@ declare namespace basic {
*/
//% block="free fall"
FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL
/**
* Raised when a 3G shock is detected
*/
//% block="3g"
ThreeG = 8, // MICROBIT_ACCELEROMETER_EVT_3G
/**
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G
}
declare namespace input {
}

View File

@ -94,7 +94,17 @@ enum class Gesture {
* Raised when the board is falling!
*/
//% block="free fall"
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL,
/**
* Raised when a 3G shock is detected
*/
//% block="3g"
ThreeG = MICROBIT_ACCELEROMETER_EVT_3G,
/**
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = MICROBIT_ACCELEROMETER_EVT_6G
};
//% color=300 weight=99
@ -117,6 +127,10 @@ namespace input {
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(4);
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
uBit.accelerometer.setRange(8);
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
}

View File

@ -83,11 +83,11 @@ namespace music {
/**
* Plays a tone through pin ``P0`` for the given duration.
* @param frequency TODO
* @param ms TODO
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone (Hz) %note=device_note|for (ms) %duration=device_beat" icon="\uf025" blockGap=8
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
export function playTone(frequency: number, ms: number): void {
pins.analogSetPitchPin(AnalogPin.P0);
pins.analogPitch(frequency, ms);
@ -95,7 +95,7 @@ namespace music {
/**
* Plays a tone through pin ``P0``.
* @param frequency TODO
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
@ -106,7 +106,7 @@ namespace music {
/**
* Rests (plays nothing) for a specified time through pin ``P0``.
* @param ms TODO
* @param ms rest duration in milliseconds (ms)
*/
//% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat"
@ -117,7 +117,7 @@ namespace music {
/**
* Gets the frequency of a note.
* @param name TODO
* @param name the note name
*/
//% weight=50 help=music/note-frequency
//% blockId=device_note block="%note"

View File

@ -128,7 +128,7 @@ namespace pins {
* @param name analog pin to set period to
* @param micros period in micro seconds. eg:20000
*/
//% help=pins/analog-set-period weight=23
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
void analogSetPeriod(AnalogPin name, int micros) {
PINOP(setAnalogPeriodUs(micros));
@ -148,10 +148,10 @@ namespace pins {
}
/**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulse`` handler.
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/
//% help=pins/pulse-micros
//% blockId=pins_pulse_duration block="pulse duration (us)"
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21
int pulseDuration() {
return pxt::lastEvent.timestamp;

View File

@ -11,7 +11,7 @@ namespace pins {
* @param toLow the lower bound of the value's target range
* @param toHigh the upper bound of the value's target range, eg: 4
*/
//% help=pins/map weight=3
//% help=pins/map weight=22
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;

View File

@ -483,7 +483,7 @@ declare namespace pins {
* @param name analog pin to set period to
* @param micros period in micro seconds. eg:20000
*/
//% help=pins/analog-set-period weight=23
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" shim=pins::analogSetPeriod
function analogSetPeriod(name: AnalogPin, micros: number): void;
@ -495,10 +495,10 @@ declare namespace pins {
function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;
/**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulse`` handler.
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/
//% help=pins/pulse-micros
//% blockId=pins_pulse_duration block="pulse duration (us)"
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 shim=pins::pulseDuration
function pulseDuration(): number;

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.125",
"version": "0.2.130",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.131"
"pxt-core": "0.2.139"
}
}

View File

@ -26,8 +26,8 @@
]
},
"files": {
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"device_show_leds\"><field name=\"LED00\">FALSE</field><field name=\"LED10\">FALSE</field><field name=\"LED20\">FALSE</field><field name=\"LED30\">FALSE</field><field name=\"LED40\">FALSE</field><field name=\"LED01\">FALSE</field><field name=\"LED11\">TRUE</field><field name=\"LED21\">FALSE</field><field name=\"LED31\">TRUE</field><field name=\"LED41\">FALSE</field><field name=\"LED02\">FALSE</field><field name=\"LED12\">FALSE</field><field name=\"LED12\">FALSE</field><field name=\"LED22\">FALSE</field><field name=\"LED32\">FALSE</field><field name=\"LED42\">FALSE</field><field name=\"LED03\">TRUE</field><field name=\"LED13\">FALSE</field><field name=\"LED23\">FALSE</field><field name=\"LED33\">FALSE</field><field name=\"LED43\">TRUE</field><field name=\"LED04\">FALSE</field><field name=\"LED14\">TRUE</field><field name=\"LED24\">TRUE</field><field name=\"LED34\">TRUE</field><field name=\"LED44\">FALSE</field></block></xml>",
"main.ts": "\n"
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n<block type=\"device_forever\">\n<statement name=\"HANDLER\">\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">TRUE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">TRUE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">TRUE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">TRUE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">TRUE</field>\n<field name=\"LED24\">TRUE</field>\n<field name=\"LED34\">TRUE</field>\n<field name=\"LED44\">FALSE</field>\n<next>\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">FALSE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">FALSE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">FALSE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">FALSE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">FALSE</field>\n<field name=\"LED24\">FALSE</field>\n<field name=\"LED34\">FALSE</field>\n<field name=\"LED44\">FALSE</field>\n</block>\n</next>\n</block>\n</statement>\n</block>\n</xml>",
"main.ts": "\r\n"
}
},
"tsprj": {
@ -63,6 +63,9 @@
"aspectRatio": 1.22
},
"compileService": {
"yottaTarget": "bbc-microbit-classic-gcc",
"yottaCorePackage": "pxt-microbit-core",
"githubCorePackage": "microsoft/pxt-microbit-core",
"gittag": "v0.1.10",
"serviceId": "ws"
},