Compare commits

...

9 Commits

11 changed files with 93 additions and 56 deletions

View File

@ -34,7 +34,7 @@ Just like Arduino, the micro:bit can be connected to and interact with sensors,
The student can program the BBC micro:bit using [visual blocks](http://www.github.com/Google/blockly) or JavaScript.
```blocks
basic.showString("BBC micro:bit!");
basic.showString("Hi!");
```
## Compile and Flash
@ -54,5 +54,10 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
The [C++ BBC micro:bit runtime](http://lancaster-university.github.io/microbit-docs/), created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
as well as a set of helper functions (such as displaying a number/image/string on the LED screen).
The JavaScript micro:bit library mirrors the functions of the C++ library.
When code is compiled to ARM machine code, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.
## Open Source
The editor for the BBC micro:bit is [open source](/open-source) on GitHub. Contributors are welcome!

View File

@ -1,7 +1,5 @@
# micro:bit - the device
The micro:bit device
The micro:bit is a very capable device with many components:
* [the USB connector](/device/usb)

View File

@ -1,7 +1,5 @@
# The micro:bit - a reactive system
The micro:bit is a reactive system.
### Computing systems
What sort of a *computing system* is the micro:bit?

View File

@ -11,16 +11,35 @@ input.onButtonPressed(Button.A, () => {
})
```
Data is also automatically streamed to serial by the ** bar graph** block
and picked up by the editor. This data can be streamed to the cloud as well.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0);
});
```
## How to read the micro:bit's serial output from your computer
Unfortunately, using the serial library requires quite a bit of a setup.
### BBC micro:bit Chrome Extension
If you are using the Google Chrome browser, you can use our extension to get serial data streaming in the editor.
* Install the [Extension for BBC micro:bit](https://chrome.google.com/webstore/detail/extension-for-bbc-microbi/cihhkhnngbjlhahcfmhekmbnnjcjdbge?hl=en-US) on the Chrome Web Store.
* Restart Chrome and open the web editor.
### Windows
You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it:
* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver
* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
#### Windows > Tera Term
* Install the terminal emulator [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm.
@ -32,7 +51,7 @@ You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to eras
Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time.
### Alternative Windows setup with Putty
#### Windows > Putty
If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions.

View File

@ -4,6 +4,6 @@ The editor is open source on GitHub under the MIT license. Contributions are wel
### Repos
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit, also includes the documentation.
* [microbit/pxt](https://github.com/Microsoft/pxt), programming experience toolkit (PXT)
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit
* [microsoft/pxt-microbit-core](https://github.com/Microsoft/pxt-microbit-core), Yotta module used to build the BBC micro:bit runtime

View File

@ -1,27 +1,35 @@
# Magnetic Force
Get the magnetic force (micro Teslas), in one of three specified dimensions.
Find the amount of magnetic force (the strength of a magnet) in the direction you say.
```sig
input.magneticForce(Dimension.X);
```
## ~hint
The micro:bit measures magnetic force with **microteslas**.
## ~
### Parameters
* dimension : [String](/reference/types/string) - one of three values specifying the axis of the force: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down); ``strength`` (the length of the vector)
* a [string](/reference/types/string) that says which direction the micro:bit should measure magnetic force in: either `x` (the left-right direction), `y` (the forward/backward direction), or `z` (the up/down direction)
### Returns
* [Number](/reference/types/number) - magnetic force, in micro-Teslas.
* a [number](/reference/types/number) of microteslas that means the strength of the magnet
### Example: metal detector
The following example uses the `magnetic force` to control the brightness of the screen. When the magnetic force increases, the center LED will appear brighter.
This program makes the center LED of the micro:bit get brighter when
the magnetic force is stronger, and dimmer when it is weaker.
```blocks
led.plot(2, 2)
basic.forever(() => {
let f = input.magneticForce(Dimension.X)
let f = input.magneticForce("x")
led.setBrightness(f / 2000)
})
```
@ -29,4 +37,3 @@ basic.forever(() => {
### See also
[compass heading](/reference/input/compass-heading)

View File

@ -1,19 +1,17 @@
# On Gesture
Register an [event handler](/reference/event-handler) that will execute whenever the user executes a gesture withthe BBC micro:bit.
Start an [event handler](/reference/event-handler) (part of the
program that will run when something happens) This handler works when
you do a **gesture** (like shake, tilt, or drop the micro:bit).
```sig
input.onGesture(Gesture.Shake,() => {
})
```
## Gestures
## Example: random number
### Example: random number
The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit.
This program shows a number from `0` to `9` when you shake the micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
@ -22,24 +20,7 @@ input.onGesture(Gesture.Shake,() => {
})
```
### Example: rock, paper, scissors
## Lessons
The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake,() => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img.showFrame(Math.random(3))
})
```
### Lessons
[bounce image](/lessons/bounce-image), [rock paper scissors](/lessons/rock-paper-scissors)
[bounce image](/lessons/bounce-image)

View File

@ -1,24 +1,33 @@
# Pin Is Pressed
Gets the pin state (pressed or not pressed), by detecting when the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit.
Find whether the pin you say is pressed or not pressed.
*Note* that this function works best when the BBC micro:bit is powered by AAA battery.
If you hold the `GND` pin with one hand and touch pin `0`, `1`, or `2` with the other,
a very small (safe) amount of electricity will flow through your body and back into
the micro:bit. This is called **completing a circuit**. It's like you're a big wire!
```sig
input.pinIsPressed(TouchPin.P0);
```
## ~hint
This function works best when the BBC:microbit is using batteries for power,
instead of the USB cable.
## ~
### Parameters
* name - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
* a [string](/reference/types/string) that holds the pin name (**P0**, **P1**, or **P2**)
### returns
* [Boolean](/reference/types/boolean) - `true` if pressed, `false` if not pressed
* a [boolean](/reference/types/boolean) that means whether the pin you say is pressed (`true` or `false`)
### Example
This example displays 1 if P0 is pressed, and 0 if P0 is not pressed:
This program shows `1` if `P0` is pressed, and `0` if `P0` is not pressed:
```blocks
basic.forever(() => {

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.156",
"version": "0.2.157",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.168"
"pxt-core": "0.2.170"
}
}

View File

@ -188,7 +188,7 @@ namespace pxsim.micro_bit {
if (text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
}
else if (pin.mode & PinFlags.Digital) {
v = pin.value > 0 ? '0%' : '100%';
v = pin.value > 0 ? "0%" : "100%";
if (text) text.textContent = pin.value > 0 ? "1" : "0";
}
else if (pin.mode & PinFlags.Touch) {
@ -382,7 +382,13 @@ svg.sim.grayscale {
stroke:grey;
stroke-width: 3px;
}
.sim-button-nut {
fill:#704A4A;
pointer-events:none;
}
.sim-button-nut:hover {
stroke:1px solid #704A4A;
}
.sim-pin:hover {
stroke:#D4AF37;
stroke-width:2px;
@ -564,17 +570,29 @@ svg.sim.grayscale {
return lg;
})
this.pinTexts = [67, 165, 275].map(x => <SVGTextElement>svg.child(this.g, "text", { class: 'sim-text-pin', x: x, y: 345 }));
this.pinTexts = [67, 165, 275].map(x => <SVGTextElement>svg.child(this.g, "text", { class: "sim-text-pin", x: x, y: 345 }));
this.buttonsOuter = []; this.buttons = [];
this.buttonsOuter.push(svg.path(this.g, "sim-button-outer", "M82.1,232.6H25.9c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C83,232.2,82.6,232.6,82.1,232.6", "A"));
const outerBtn = (left: number, top: number) => {
const btnr = 4;
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 });
}
outerBtn(25.9, 176.4);
this.buttons.push(svg.path(this.g, "sim-button", "M69.7,203.5c0,8.7-7,15.7-15.7,15.7s-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7S69.7,194.9,69.7,203.5"));
this.buttonsOuter.push(svg.path(this.g, "sim-button-outer", "M474.3,232.6h-56.2c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C475.3,232.2,474.8,232.6,474.3,232.6", "B"));
outerBtn(418.1, 176.4);
this.buttons.push(svg.path(this.g, "sim-button", "M461.9,203.5c0,8.7-7,15.7-15.7,15.7c-8.7,0-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7C454.9,187.8,461.9,194.9,461.9,203.5"));
this.buttonsOuter.push(svg.child(this.g, "rect", { class: "sim-button-outer", x: 417, y: 250, width: 58, height: 58, rx: 1, ry: 1, title: "A+B" }));
outerBtn(417, 250);
this.buttons.push(svg.child(this.g, "circle", { class: "sim-button", cx: 446, cy: 278, r: 16.5 }));
(<any>this.buttonsOuter[2]).style.visibility = 'hidden';
(<any>this.buttons[2]).style.visibility = 'hidden';
(<any>this.buttonsOuter[2]).style.visibility = "hidden";
(<any>this.buttons[2]).style.visibility = "hidden";
svg.path(this.g, "sim-label", "M35.7,376.4c0-2.8,2.1-5.1,5.5-5.1c3.3,0,5.5,2.4,5.5,5.1v4.7c0,2.8-2.2,5.1-5.5,5.1c-3.3,0-5.5-2.4-5.5-5.1V376.4zM43.3,376.4c0-1.3-0.8-2.3-2.2-2.3c-1.3,0-2.1,1.1-2.1,2.3v4.7c0,1.2,0.8,2.3,2.1,2.3c1.3,0,2.2-1.1,2.2-2.3V376.4z");
svg.path(this.g, "sim-label", "M136.2,374.1c2.8,0,3.4-0.8,3.4-2.5h2.9v14.3h-3.4v-9.5h-3V374.1z");

View File

@ -17,6 +17,8 @@
<Application Id="App" StartPage="https://m.pxt.io/">
<uap:ApplicationContentUriRules>
<uap:Rule Match="https://m.pxt.io/" Type="include" WindowsRuntimeAccess="all" />
<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">