Compare commits

...

23 Commits

Author SHA1 Message Date
Peli de Halleux
be284c5e52 0.2.141 2016-06-01 16:13:16 -07:00
Peli de Halleux
d59d7cb19f Bump pxt-core to 0.2.153 2016-06-01 16:13:14 -07:00
Ron Hale-Evans
28d522175b Second edit pass. Needs better image examples? 2016-06-01 16:02:22 -07:00
Peli de Halleux
7b74428275 more glow / stop sound on player stop 2016-06-01 15:45:40 -07:00
Peli de Halleux
c5571c20c7 updated release notes 2016-06-01 15:06:47 -07:00
Peli de Halleux
fc97b59d0e 0.2.140 2016-06-01 13:36:58 -07:00
Peli de Halleux
8417d10ad3 Bump pxt-core to 0.2.152 2016-06-01 13:36:56 -07:00
Ron Hale-Evans
1a6d47a1c9 First edit pass. Please push to server. 2016-06-01 13:35:53 -07:00
Peli de Halleux
d74702353f 0.2.139 2016-06-01 09:11:55 -07:00
Peli de Halleux
53922986b1 Bump pxt-core to 0.2.149 2016-06-01 09:11:53 -07:00
Peli de Halleux
230de475d1 0.2.138 2016-06-01 08:52:21 -07:00
Peli de Halleux
9b1d2085ba Bump pxt-core to 0.2.148 2016-06-01 08:52:20 -07:00
Peli de Halleux
246d81ffd5 0.2.137 2016-06-01 08:13:26 -07:00
Peli de Halleux
3b2729d9d8 0.2.136 2016-06-01 07:42:41 -07:00
Peli de Halleux
571ae8337f Bump pxt-core to 0.2.147 2016-06-01 07:42:39 -07:00
Peli de Halleux
cc2d18b969 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-06-01 07:42:37 -07:00
Peli de Halleux
fd02bd9407 updated docs menu 2016-06-01 07:42:03 -07:00
Ron Hale-Evans
6429b57081 Improve docs (terminology, hyperlinks). 2016-05-31 17:17:36 -07:00
Ron Hale-Evans
5650f7dc35 Finishing pass on send/receive number. Examples distributed more sensibly. 2016-05-31 17:02:22 -07:00
Ron Hale-Evans
a9cfe83bdf Target=kids so removing all 'Important Security Considerations' for now. 2016-05-31 12:06:03 -07:00
Ron Hale-Evans
f9409b5fb5 Mailbot example works now. 2016-05-31 11:44:20 -07:00
Tom Ball
7f9f14df18 rename 2016-05-27 21:40:59 -07:00
Ron Hale-Evans
a383060b4d Improved examples; last one needs work. 2016-05-27 16:22:38 -07:00
23 changed files with 225 additions and 112 deletions

View File

@@ -1,14 +1,14 @@
# Getting started
Are you ready to build cool BBC micro:bit programs? For each challenge, reorder the blocks to recreate the program.
Are you ready to build cool BBC micro:bit programs?
## Open [https://m.pxt.io](/) and create a new **Blocks Editor** project
Here are some challenges for you. Unscramble the blocks in the editor
to make real programs that work!
## Basic
### Show LEDs
### Show leds
Use the blocks below to draw a figure on the screen. You can redo the smiley face or try something else!
Draw something in the editor with this block. You can draw another
smiley face, or try something else.
```shuffle
basic.showLeds(`
@@ -20,15 +20,16 @@ basic.showLeds(`
`)
```
To transfer your code to the BBC micro:bit,
* connect your micro:bit to the computer using the USB cable
* click on **Download**
* drag&drop the **.hex** file into the **MICROBIT** drive
* wait till the yellow light is done blinking!
To move your program from your computer to the BBC micro:bit:
* Connect your micro:bit to the computer with the USB cable.
* Click **Compile**.
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
* Wait until the yellow light stops blinking!
### Show animation Forever
### Show animation forever
Show one image after the other to create an animation by snapping them together.
Show one picture after another by snapping blocks together to create an
animation (like a cartoon)!
```blocks
basic.showLeds(`
@@ -47,12 +48,20 @@ Show one image after the other to create an animation by snapping them together.
`)
```
To move your program from your computer to the BBC micro:bit:
* Connect your micro:bit to the computer with the USB cable.
* Click **Compile**.
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
* Wait until the yellow light stops blinking!
### Repeat forever
### Repeat Forever
Use the ``forever`` block to repeat your code and have a continuous animation.
Make an animation that never stops with the ``forever`` block.
Unscramble these blocks in the editor to make an animation that first
shows a happy face, then an unhappy face, then a happy face, and never
stops.
Unsuffle the blocks to create a happy, unhappy animation.... or changes the image to make it your own!
```shuffle
basic.forever(() => {
basic.showLeds(`
@@ -72,25 +81,34 @@ basic.forever(() => {
});
```
### Your turn now!
### Your turn!
Use the blocks ``show leds`` and ``forever``
to create your own custom awesome animation!
You can also change the pictures to make your own animation.
Make your own awesome animation with the ``show leds`` and ``forever``
blocks.
## Inputs
#### ~hint
You can make your animation longer if you use more than two pictures.
#### ~
### Button A and B
Unshuffle the blocks so that the micro:bit shows "YES" when button A is pressed, and "NO" when B is pressed.
The key idea is that all the blocks nested under `on button ... pressed` will run when that button is pressed.
This program will show the word `banana` on the LED
screen when you press button `B`.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("AAAAA");
input.onButtonPressed(Button.B, () => {
basic.showString("banana");
});
```
Try to unshuffle those blocks:
Now try to unscramble these blocks in the editor so that the micro:bit
shows **YES** when you press button `A` and **NO** when when you press
button `B`. All of the blocks under `on button A pressed` or `on
button B pressed` should run when you press that button.
```shuffle
input.onButtonPressed(Button.A, () => {
basic.showString("YES");
@@ -102,9 +120,13 @@ input.onButtonPressed(Button.B, () => {
### Shake
Using the data from the **accelerometer**, it is possible to detect that the BBC micro:bit is being shaken.
You can find when someone is shaking the BBC micro:bit by checking its
**accelerometer** (it finds whether the micro:bit is speeding up or
slowing down).
Unscramble these blocks in the editor to show a frownie when someone
shakes the micro:bit.
Unshuffle the code to display a frownie when shaken.
```shuffle
input.onGesture(Gesture.Shake, () => {
basic.showLeds(`
@@ -116,12 +138,18 @@ input.onGesture(Gesture.Shake, () => {
});
```
### Tilting
### Tilting with gestures
Aside from shake, it is also possible to detect tilt left and right, logo up and down or face up and down.
Let's build a rock paper scissors game where you turn the micro:bit left to display paper, right to display scissors and down to display rock.
You can also find when someone is tilting the micro:bit left or right,
face up or face down, and logo up or logo down (the logo is the yellow
oval picture at the top of the board).
Try to build a Rock Paper Scissors game where you tilt the micro:bit
left to show paper, right to show scissors, and down to show rock.
Unscramble these blocks in the editor and try this program on the
micro:bit itself!
Unshuffle and try this code on the micro:bit itself!
```shuffle
input.onGesture(Gesture.TiltLeft, () => {
basic.showLeds(`
@@ -151,10 +179,14 @@ input.onGesture(Gesture.TiltRight, () => {
### Pins
It is possible to use the pins (big metal bar at the bottom of the board) as button. Hold the ``GND`` button with one hand and press the ``0`` pin
(called ``P0``) with the other hand to trigger a pin pressed.
You can also use the pins as buttons. (The pins are the holes in the
metal bar at the bottom of the micro:bit board.) For example, hold
the ``GND`` button with one hand and touch the ``0`` pin (called
``P0``) with your other hand to tell the micro:bit you're pressing it.
Unscramble the blocks in the editor to show a smiley when you press
pin ``P0``.
Unshuffle the blocks to display a smiley when pin ``P0`` is pressed.
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
@@ -166,6 +198,7 @@ input.onPinPressed(TouchPin.P0, () => {
});
```
### Your turn now!
### Your turn!
Use the screen, buttons, gestures, pins to create a fun game using the micro:bit.
Use the screen, buttons, gestures, and pins to make your own fun game
with the BBC micro:bit!

View File

@@ -18,4 +18,31 @@ To remove a package, click on the garbage button in the file list next to the pa
## Publishing libraries
Packages can be published from the pxt command line. We are still sorting out the details.
Packages can be published from the pxt command line. We are still sorting out the details.
## Localizing libraries
It is possible to package localization strings for the **jsDoc** description associated to the API in the package.
When compiling a package, the PXT compiler generates a `strings.json` file under the `_locales/` folder.
This file contains a map from the symbol name to the en
```
{
...
"basic": "Provides access to basic micro:bit functionality.",
...
}
```
```
{
"basic.clearScreen": "Eteint toutes les diodes."
}
```
```
_locales/
_locales/fr/strings.json
_locales/pt-BR/strings.json
```

View File

@@ -0,0 +1,34 @@
## Getting started
• Go to https://m.pxt.io/
• To create a new project, click new Project
Tap or click Blocks.
## Step 1
Use [show leds](/reference/basic/showLeds) and make your code look like this:
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
```
Once you are done coding, don't forget to run your code with the Play button.
## Step 2
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clearScreen) to turn off the LEDs.
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
```

View File

@@ -55,7 +55,8 @@ input.onGesture(Gesture.Shake, () => {
```
Next, when you shake the micro:bit, it should pick a random number from `0` to `2`
and store it in the variable.
and store it in the variable `weapon`. (This variable is named `weapon` because
rock, paper, and scissors are the weapons you use to battle your friends!)
Add a ``set`` block with a variable. Then add a ``pick random`` block,
and store the random number in the variable,
@@ -230,4 +231,4 @@ input.onButtonPressed(Button.B, () => {
## Step 8: Hacking Rock Paper Scissors
How else can you make your game better?
Ever hear of [Rock Paper Scissors Spock Lizard](https://en.wikipedia.org/wiki/Rock-paper-scissors#Additional_weapons)?
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?

View File

@@ -2,18 +2,6 @@
Registers code to run when a packet is received over ``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.onDataReceived(() => {})
```
### Parameters
* body - is an action

View File

@@ -1,26 +1,15 @@
# Receive Number
Reads the next radio packet if any and returns the first number.
## 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.receiveNumber()
```
Receives the next number sent by a micro:bit in the same ``radio`` group.
### Return value
* the first number [number](/reference/types/number) of the packet if any. `0` otherwise.
* the first [number](/reference/types/number) that the micro:bit received. If it did not receive any numbers, this function will return `0`.
### Examples
### Example: Simple number receiver
Read the number broadcasted by other micro:bits.
This example receives the number broadcasted another micro:bit and shows it
as a bar graph.
```blocks
radio.onDataReceived(() => {
@@ -28,7 +17,42 @@ radio.onDataReceived(() => {
})
```
### Example: Light level receiver
This example shows the light level from the [light level sender example](/reference/input/send-number)
as a number.
```blocks
radio.setGroup(99)
basic.forever(() => {
let level = radio.receiveNumber()
basic.showNumber(level)
})
```
### Example: Mailbot
This example receives the light level from the [light level sender example](/reference/input/send-number)
and shows a text string like **ALERT** if the light level becomes much brighter.
To find when the mail arrives, you can put the light level sender in your mailbox and it will
tell you when someone opens the box. You can try this with a normal
box too, like a present for a friend.
```blocks
radio.setGroup(99)
let max = 0
basic.forever(() => {
let level = radio.receiveNumber()
if (level > max) {
max = level
}
if (max > 10) {
basic.showString("ALERT")
}
})
```
### See also
[receive number](/reference/input/receive-number), [on data received](/reference/radio/on-data-received)
[send number](/reference/input/send-number), [on data received](/reference/radio/on-data-received)

View File

@@ -1,26 +1,16 @@
# Send Number
Broadcasts a number 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.sendNumber(0)
```
Broadcast a number to other micro:bits connected via ``radio``.
### Parameters
* packet - a number to be transmitted.
* num - a number to send.
### Examples
### Example: Broadcasting acceleration
Broadcasts the value of ``acceleration`` x to other micro:bits.
This example broadcasts the value of your micro:bit's ``acceleration`` in the `x` direction
(left and right) to other micro:bits.
This kind of program might be useful in a model car or model rocket.
```blocks
input.onButtonPressed(Button.A, () => {
@@ -28,6 +18,20 @@ input.onButtonPressed(Button.A, () => {
})
```
### Light level sender
This example broadcasts the level of the light around it.
You can do some interesting things with it if you use it along with the
[Mailbot](/reference/radio/receive-number) example.
```blocks
radio.setGroup(99)
basic.forever(() => {
let level = input.lightLevel()
radio.sendNumber(level)
})
```
### See also
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)

View File

@@ -4,18 +4,6 @@ Sets the group id for ``radio`` communications. A micro:bit can only listen to o
Unless specified, the group id is automatically inferred from the script source. Every script with the same exact source code with start with the same group id.
## 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.setGroup(1)
```
### Parameters
* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``.

View File

@@ -4,7 +4,12 @@
basic.forever(() => { basic.showString("RELEASE NOTES"); });
```
## May 2017
## June 2016
* It is now possible to stream data into the cloud (Azure) from the PXT editor. Simply click on the log view to get started.
* Documentation column pops up for large screen to avoid switching between docs and editor.
## May 2016
We're happy to announce [m.pxt.io](https://m.pxt.io), an Blocks/JavaScript editor for the [BBC micro:bit](https://www.microbit.co.uk).
The editor is [open source](/open-source) on GitHub. Send us your PR!

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.135",
"version": "0.2.141",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.146"
"pxt-core": "0.2.153"
}
}

View File

@@ -94,13 +94,17 @@
"path": "/about"
},
{
"name": "Lessons",
"path": "/lessons"
"name": "Getting Started",
"path": "/getting-started"
},
{
"name": "Reference",
"path": "/reference"
},
{
"name": "Lessons",
"path": "/lessons"
},
{
"name": "Device",
"path": "/device"

View File

@@ -446,7 +446,7 @@ svg.sim.grayscale {
}
@keyframes sim-theme-glow-animation {
from { opacity: 1; }
to { opacity: 0.8; }
to { opacity: 0.75; }
}
.sim-flash {

View File

@@ -42,14 +42,14 @@ namespace pxsim {
constructor(private runtime: Runtime) { }
listen(id: number, evid: number, handler: RefAction) {
let k = id + ':' + evid;
let k = id + ":" + evid;
let queue = this.queues[k];
if (!queue) queue = this.queues[k] = new EventQueue<number>(this.runtime);
queue.handler = handler;
}
queue(id: number, evid: number, value: number = 0) {
let k = id + ':' + evid;
let k = id + ":" + evid;
let queue = this.queues[k];
if (queue) queue.push(value);
}
@@ -122,7 +122,7 @@ namespace pxsim {
broadcast(msg: number) {
Runtime.postMessage(<SimulatorEventBusMessage>{
type: 'eventbus',
type: "eventbus",
id: DAL.MES_BROADCAST_GENERAL_ID,
eventid: msg,
power: this.power,
@@ -551,12 +551,12 @@ namespace pxsim {
default: theme = pxsim.micro_bit.randomTheme();
}
console.log('setting up microbit simulator')
console.log("setting up microbit simulator")
let view = new pxsim.micro_bit.MicrobitBoardSvg({
theme: theme,
runtime: runtime
})
document.body.innerHTML = ''; // clear children
document.body.innerHTML = ""; // clear children
document.body.appendChild(view.element);
return Promise.resolve();
@@ -581,22 +581,27 @@ namespace pxsim {
}
readSerial() {
let v = this.serialIn.shift() || '';
let v = this.serialIn.shift() || "";
return v;
}
serialOutBuffer: string = '';
kill() {
super.kill();
AudioContextManager.stop();
}
serialOutBuffer: string = "";
writeSerial(s: string) {
for (let i = 0; i < s.length; ++i) {
let c = s[i];
this.serialOutBuffer += c;
if (c == '\n') {
if (c == "\n") {
Runtime.postMessage(<SimulatorSerialMessage>{
type: 'serial',
type: "serial",
data: this.serialOutBuffer,
id: runtime.id
})
this.serialOutBuffer = ''
this.serialOutBuffer = ""
break;
}
}