Compare commits

..

5 Commits

Author SHA1 Message Date
786c5f9733 0.2.158 2016-06-09 21:14:54 -07:00
0cdedd02b4 updated rendering of buttons 2016-06-09 21:14:33 -07:00
aba028b1e8 Rewrote in simple language. Updated code example. 2016-06-09 18:25:59 -07:00
3049c88d5b Simulator warnings, etc. 2016-06-09 15:30:47 -07:00
8239329c2e Rewrote with simple language 2016-06-09 15:09:48 -07:00
14 changed files with 104 additions and 67 deletions

View File

@ -1,6 +1,10 @@
# Compass Heading
Get the compass heading of the micro:bit in degrees. Your micro:bit has a built-in **magnetometer** so it can your direction with respect to the North Magnetic Pole.
Find which direction on a compass the micro:bit is facing.
The micro:bit measures the **compass heading** from `0` to `360`
degrees with its **magnetometer** chip. Different numbers mean north,
east, south, and west.
```sig
input.compassHeading();
@ -8,15 +12,12 @@ input.compassHeading();
### Returns
* [Number](/reference/types/number) - the heading in degrees (0 to 360 degrees). If the compass is calibrating, it returns ``-1003``.
## Simulator
Calibration does not work on the simulator.
* a [number](/reference/types/number) from `0` to `360` degrees, which means the compass heading. If the compass isn't ready, it returns `-1003`.
### Example
The following code gets the compass heading and stores it in the `degrees` variable:
This program finds the compass heading and stores it in the
`degrees` variable.
```blocks
let degrees = input.compassHeading()
@ -24,13 +25,16 @@ let degrees = input.compassHeading()
### ~hint
When running code with this function in a web browser, click and drag the on-screen compass needle to change heading.
When you run a program that uses this function in a browser, click and drag
the compass needle on the screen to change the compass heading.
### ~
### Example: compass
The following example gets the `compass heading` and then displays a letter depending on the value of `degrees`: N for north, E for East, S for South, and W for West.
This program finds the compass heading and then shows a letter
that means whether the micro:bit is facing north (N), south (S),
east (E), or west (W).
```blocks
basic.forever(() => {
@ -47,11 +51,13 @@ basic.forever(() => {
### Calibration
On the first use of the compass, the **calibration** procedure will automatically start. The user must draw a circle with the device until it is fully calibrated.
Every time you start to use the compass (for example, if you have just
turned the micro:bit on), the micro:bit will start to **calibrate**
(adjust itself). It will ask you to draw a circle by tilting the
micro:bit.
An enclosure made from metal, or using in proximity of metal objects, might affect the accuracy of the reading and calibration.
During calibration, ``compass heading`` returns ``-1003``.
If you are calibrating or using the compass near metal, it might
confuse the micro:bit.
### Lessons
@ -60,4 +66,3 @@ During calibration, ``compass heading`` returns ``-1003``.
### See also
[acceleration](/reference/input/acceleration)

View File

@ -1,45 +1,58 @@
# Rotation
Get a rotation angle in degrees inferred from the accelerometer readings.
Find how much the micro:bit is tilted in different directions.
```sig
input.rotation(Rotation.Roll);
```
## ~hint
The BBC micro:bit has a part called the **accelerometer** that can
check how the micro:bit is moving.
## ~
### Parameters
* kind: [String](/reference/types/string) - one of values specifying the kind of rotation: ``pitch`` (up/down around the ``x`` axis); ``roll`` (left/right around the ``y`` axis)
* which direction you are checking: `Rotation.Pitch` (up and down) or `Rotation.Roll` (left and right)
### Returns
* [Number](/reference/types/number) - angle, in degrees.
* a [number](/reference/types/number) that means how much the microbit is tilted in the direction you say, from `0` to `360` degrees
### Example: micro:bit leveller
### Example: micro:bit leveler
The following example uses the `rotation` and the `plot leds` function to help you move the BBC micro:bit until it's level: when it is level, a smiley shows up on the screen. When running this code in a web browser, move your mouse to simulate the rotation.
This program helps you move the BBC micro:bit until it is level. When
it is level, the micro:bit shows a smiley.
```sig
If you are running this program in a browser, you can tilt the
micro:bit with your mouse.
```blocks
let pitch = 0;
basic.forever(() => {
let pitch = input.rotation(Rotation.Pitch)
let roll = input.rotation(Rotation.Roll)
pitch = input.rotation(Rotation.Pitch);
let roll = input.rotation(Rotation.Roll);
if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) {
basic.plotLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. # . # .
. . . . .
. . . . .
# . . . #
. # # # .
`);
} else {
basic.plotLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
}
})
basic.showLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`);
}
});
```
### See also

View File

@ -7,6 +7,10 @@ Run part of a program when the micro:bit receives a
* the part of the program to run when the micro:bit receives information over ``radio``.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program keeps sending numbers that says how fast the micro:bit is

View File

@ -2,10 +2,14 @@
Receives the next number sent by a micro:bit in the same ``radio`` group.
### Return value
### Returns
* the first [number](/reference/types/number) that the micro:bit received. If it did not receive any numbers, this function will return `0`.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Simple number receiver
This example receives the number broadcasted another micro:bit and shows it

View File

@ -6,10 +6,14 @@ Find the next string sent by `radio` from another micro:bit.
radio.receiveString()
```
### Return value
### Returns
* the first [string](/reference/types/string) that was sent. If no string was sent, then this function returns an empty (blank) string.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Simple receiver
Show the string sent by another micro:bit.

View File

@ -13,7 +13,7 @@ it needs to run **receive number** first.
* a [number](/reference/types/number) between `255` and `0` that means
how strong the signal is.
## Simulator
### Simulator
This function only works on the micro:bit, not in browsers.

View File

@ -6,6 +6,10 @@ Broadcast a number to other micro:bits connected via ``radio``.
* num - a number to send.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Broadcasting acceleration
This example broadcasts the value of your micro:bit's ``acceleration`` in the `x` direction

View File

@ -1,7 +1,5 @@
# Send String
Sends a string to other micro:bits in the area connected by radio.
```sig
@ -12,6 +10,12 @@ radio.sendString("Hello!")
* `text` is a [String](/reference/types/string) to send by radio.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example: Two-way radio
If you load this program onto two or more micro:bits, you can send a code word from one of them to the others by pressing button `A`.

View File

@ -14,6 +14,10 @@ to talk to each other because they will have the same group ID.
* ``id`` is a [number](/reference/types/number) from ``0`` to ``255``.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program makes the group ID equal 128.

View File

@ -8,7 +8,7 @@ The scientific name for the strength of the ``radio`` signal is
can be measured as -30 dBm, and a strength of `7` can be
measured as +4 dBm.
## Range
### Range
If your micro:bit is sending with a strength of `7`, and you are in
an open area without many other computers around, the micro:bit signal
@ -19,6 +19,10 @@ can reach as far as 70 meters (about 230 feet).
* a [number](/reference/types/number) between ``0`` and ``7`` that
means how strong the signal is.
### Simulator
This function only works on the micro:bit, not in browsers.
### Example
This program makes the ``radio`` send at full strength.

View File

@ -9,21 +9,11 @@ The format for received data printed to serial is as follows
- [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.
### Simulator
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.writeValueToSerial()
```
### Parameters
* None
This function only works on the micro:bit, not in browsers.
### Examples

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.157",
"version": "0.2.158",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",

View File

@ -578,11 +578,13 @@ svg.sim.grayscale {
const btnw = 56.2;
const btnn = 6;
const btnnm = 10
this.buttonsOuter.push(svg.child(this.g, "rect", { class: "sim-button-outer", x: left, y: top, rx: btnr, ry: btnr, width: btnw, height: btnw }));
svg.child(this.g, "circle", { class: "sim-button-nut", cx: left + btnnm, cy: top + btnnm, r: btnn });
svg.child(this.g, "circle", { class: "sim-button-nut", cx: left + btnnm, cy: top + btnw - btnnm, r: btnn });
svg.child(this.g, "circle", { class: "sim-button-nut", cx: left + btnw - btnnm, cy: top + btnw - btnnm, r: btnn });
svg.child(this.g, "circle", { class: "sim-button-nut", cx: left + btnw - btnnm, cy: top + btnnm, r: btnn });
let btng = svg.child(this.g, "g");
this.buttonsOuter.push(btng);
svg.child(btng, "rect", { class: "sim-button-outer", x: left, y: top, rx: btnr, ry: btnr, width: btnw, height: btnw });
svg.child(btng, "circle", { class: "sim-button-nut", cx: left + btnnm, cy: top + btnnm, r: btnn });
svg.child(btng, "circle", { class: "sim-button-nut", cx: left + btnnm, cy: top + btnw - btnnm, r: btnn });
svg.child(btng, "circle", { class: "sim-button-nut", cx: left + btnw - btnnm, cy: top + btnw - btnnm, r: btnn });
svg.child(btng, "circle", { class: "sim-button-nut", cx: left + btnw - btnnm, cy: top + btnnm, r: btnn });
}
outerBtn(25.9, 176.4);

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="39122940-ab16-4cd4-a0ce-79a3eb863ecf" Version="0.1.4.0" Publisher="CN=jhalleux" />
<Identity Name="39122940-ab16-4cd4-a0ce-79a3eb863ecf" Version="0.1.5.0" Publisher="CN=jhalleux" />
<mp:PhoneIdentity PhoneProductId="39122940-ab16-4cd4-a0ce-79a3eb863ecf" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>codemicrobitapp</DisplayName>
<DisplayName>codethemicrobit</DisplayName>
<PublisherDisplayName>Microsoft</PublisherDisplayName>
<Logo>images\storelogo.png</Logo>
</Properties>
@ -20,8 +20,8 @@
<uap:Rule Match="https://codemicrobit.com/" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://codethemicrobit.com/" Type="include" WindowsRuntimeAccess="all" />
</uap:ApplicationContentUriRules>
<uap:VisualElements DisplayName="m.pxt.io" Description="Code editors for the BBC micro:bit" BackgroundColor="white" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" ShortName="m.pxt.io">
<uap:VisualElements DisplayName="codethemicrobit" Description="Code editors for the BBC micro:bit" BackgroundColor="white" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" ShortName="code the micro:bit">
</uap:DefaultTile>
<uap:SplashScreen Image="images\splashscreen.png" />
</uap:VisualElements>
@ -29,7 +29,6 @@
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="microbithex">
<uap:DisplayName>BBC micro:bit binary file</uap:DisplayName>
<uap:InfoTip>.hex file created with m.pxt.io or microbit.co.uk</uap:InfoTip>
<uap:SupportedFileTypes>
<uap:FileType ContentType="application/x-microbit-hex">.hex</uap:FileType>
</uap:SupportedFileTypes>