Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be284c5e52 | ||
|
|
d59d7cb19f | ||
|
|
28d522175b | ||
|
|
7b74428275 | ||
|
|
c5571c20c7 | ||
|
|
fc97b59d0e | ||
|
|
8417d10ad3 | ||
|
|
1a6d47a1c9 | ||
|
|
d74702353f | ||
|
|
53922986b1 | ||
|
|
230de475d1 | ||
|
|
9b1d2085ba | ||
|
|
246d81ffd5 | ||
|
|
3b2729d9d8 | ||
|
|
571ae8337f | ||
|
|
cc2d18b969 | ||
|
|
fd02bd9407 | ||
|
|
6429b57081 | ||
|
|
5650f7dc35 | ||
|
|
a9cfe83bdf | ||
|
|
f9409b5fb5 | ||
|
|
7f9f14df18 | ||
|
|
a383060b4d |
@@ -1,14 +1,14 @@
|
|||||||
# Getting started
|
# 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
|
Draw something in the editor with this block. You can draw another
|
||||||
|
smiley face, or try something else.
|
||||||
Use the blocks below to draw a figure on the screen. You can redo the smiley face or try something else!
|
|
||||||
|
|
||||||
```shuffle
|
```shuffle
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
@@ -20,15 +20,16 @@ basic.showLeds(`
|
|||||||
`)
|
`)
|
||||||
```
|
```
|
||||||
|
|
||||||
To transfer your code to the BBC micro:bit,
|
To move your program from your computer to the BBC micro:bit:
|
||||||
* connect your micro:bit to the computer using the USB cable
|
* Connect your micro:bit to the computer with the USB cable.
|
||||||
* click on **Download**
|
* Click **Compile**.
|
||||||
* drag&drop the **.hex** file into the **MICROBIT** drive
|
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
|
||||||
* wait till the yellow light is done blinking!
|
* 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
|
```blocks
|
||||||
basic.showLeds(`
|
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
|
```shuffle
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
@@ -72,25 +81,34 @@ basic.forever(() => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Your turn now!
|
### Your turn!
|
||||||
|
|
||||||
Use the blocks ``show leds`` and ``forever``
|
You can also change the pictures to make your own animation.
|
||||||
to create your own custom awesome 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
|
### 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.
|
This program will show the word `banana` on the LED
|
||||||
The key idea is that all the blocks nested under `on button ... pressed` will run when that button is pressed.
|
screen when you press button `B`.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.B, () => {
|
||||||
basic.showString("AAAAA");
|
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
|
```shuffle
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
basic.showString("YES");
|
basic.showString("YES");
|
||||||
@@ -102,9 +120,13 @@ input.onButtonPressed(Button.B, () => {
|
|||||||
|
|
||||||
### Shake
|
### 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
|
```shuffle
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
basic.showLeds(`
|
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.
|
You can also find when someone is tilting the micro:bit left or right,
|
||||||
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.
|
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
|
```shuffle
|
||||||
input.onGesture(Gesture.TiltLeft, () => {
|
input.onGesture(Gesture.TiltLeft, () => {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
@@ -151,10 +179,14 @@ input.onGesture(Gesture.TiltRight, () => {
|
|||||||
|
|
||||||
### Pins
|
### 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
|
You can also use the pins as buttons. (The pins are the holes in the
|
||||||
(called ``P0``) with the other hand to trigger a pin pressed.
|
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
|
```shuffle
|
||||||
input.onPinPressed(TouchPin.P0, () => {
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
basic.showLeds(`
|
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!
|
||||||
|
|||||||
@@ -18,4 +18,31 @@ To remove a package, click on the garbage button in the file list next to the pa
|
|||||||
|
|
||||||
## Publishing libraries
|
## 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
|
||||||
|
```
|
||||||
|
|||||||
34
docs/projects/a1-display.md
Normal 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();
|
||||||
|
```
|
||||||
@@ -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`
|
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,
|
Add a ``set`` block with a variable. Then add a ``pick random`` block,
|
||||||
and store the random number in the variable,
|
and store the random number in the variable,
|
||||||
@@ -230,4 +231,4 @@ input.onButtonPressed(Button.B, () => {
|
|||||||
## Step 8: Hacking Rock Paper Scissors
|
## Step 8: Hacking Rock Paper Scissors
|
||||||
|
|
||||||
How else can you make your game better?
|
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)?
|
||||||
|
|||||||
@@ -2,18 +2,6 @@
|
|||||||
|
|
||||||
Registers code to run when a packet is received over ``radio``.
|
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
|
### Parameters
|
||||||
|
|
||||||
* body - is an action
|
* body - is an action
|
||||||
|
|||||||
@@ -1,26 +1,15 @@
|
|||||||
# Receive Number
|
# Receive Number
|
||||||
|
|
||||||
Reads the next radio packet if any and returns the first number.
|
Receives the next number sent by a micro:bit in the same ``radio`` group.
|
||||||
|
|
||||||
## 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()
|
|
||||||
```
|
|
||||||
|
|
||||||
### Return value
|
### 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
|
```blocks
|
||||||
radio.onDataReceived(() => {
|
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
|
### 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)
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,16 @@
|
|||||||
# Send Number
|
# Send Number
|
||||||
|
|
||||||
Broadcasts a number data packet to other micro:bits connected via ``radio``.
|
Broadcast a number 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)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Parameters
|
### 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
|
```blocks
|
||||||
input.onButtonPressed(Button.A, () => {
|
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
|
### See also
|
||||||
|
|
||||||
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
|
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
|
||||||
|
|||||||
@@ -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.
|
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
|
### Parameters
|
||||||
|
|
||||||
* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``.
|
* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``.
|
||||||
|
|||||||
@@ -4,7 +4,12 @@
|
|||||||
basic.forever(() => { basic.showString("RELEASE NOTES"); });
|
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).
|
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!
|
The editor is [open source](/open-source) on GitHub. Send us your PR!
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.135",
|
"version": "0.2.141",
|
||||||
"description": "BBC micro:bit target for PXT",
|
"description": "BBC micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.2.146"
|
"pxt-core": "0.2.153"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,13 +94,17 @@
|
|||||||
"path": "/about"
|
"path": "/about"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Lessons",
|
"name": "Getting Started",
|
||||||
"path": "/lessons"
|
"path": "/getting-started"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Reference",
|
"name": "Reference",
|
||||||
"path": "/reference"
|
"path": "/reference"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Lessons",
|
||||||
|
"path": "/lessons"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Device",
|
"name": "Device",
|
||||||
"path": "/device"
|
"path": "/device"
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ svg.sim.grayscale {
|
|||||||
}
|
}
|
||||||
@keyframes sim-theme-glow-animation {
|
@keyframes sim-theme-glow-animation {
|
||||||
from { opacity: 1; }
|
from { opacity: 1; }
|
||||||
to { opacity: 0.8; }
|
to { opacity: 0.75; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.sim-flash {
|
.sim-flash {
|
||||||
|
|||||||
25
sim/state.ts
@@ -42,14 +42,14 @@ namespace pxsim {
|
|||||||
constructor(private runtime: Runtime) { }
|
constructor(private runtime: Runtime) { }
|
||||||
|
|
||||||
listen(id: number, evid: number, handler: RefAction) {
|
listen(id: number, evid: number, handler: RefAction) {
|
||||||
let k = id + ':' + evid;
|
let k = id + ":" + evid;
|
||||||
let queue = this.queues[k];
|
let queue = this.queues[k];
|
||||||
if (!queue) queue = this.queues[k] = new EventQueue<number>(this.runtime);
|
if (!queue) queue = this.queues[k] = new EventQueue<number>(this.runtime);
|
||||||
queue.handler = handler;
|
queue.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue(id: number, evid: number, value: number = 0) {
|
queue(id: number, evid: number, value: number = 0) {
|
||||||
let k = id + ':' + evid;
|
let k = id + ":" + evid;
|
||||||
let queue = this.queues[k];
|
let queue = this.queues[k];
|
||||||
if (queue) queue.push(value);
|
if (queue) queue.push(value);
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
broadcast(msg: number) {
|
broadcast(msg: number) {
|
||||||
Runtime.postMessage(<SimulatorEventBusMessage>{
|
Runtime.postMessage(<SimulatorEventBusMessage>{
|
||||||
type: 'eventbus',
|
type: "eventbus",
|
||||||
id: DAL.MES_BROADCAST_GENERAL_ID,
|
id: DAL.MES_BROADCAST_GENERAL_ID,
|
||||||
eventid: msg,
|
eventid: msg,
|
||||||
power: this.power,
|
power: this.power,
|
||||||
@@ -551,12 +551,12 @@ namespace pxsim {
|
|||||||
default: theme = pxsim.micro_bit.randomTheme();
|
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({
|
let view = new pxsim.micro_bit.MicrobitBoardSvg({
|
||||||
theme: theme,
|
theme: theme,
|
||||||
runtime: runtime
|
runtime: runtime
|
||||||
})
|
})
|
||||||
document.body.innerHTML = ''; // clear children
|
document.body.innerHTML = ""; // clear children
|
||||||
document.body.appendChild(view.element);
|
document.body.appendChild(view.element);
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -581,22 +581,27 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readSerial() {
|
readSerial() {
|
||||||
let v = this.serialIn.shift() || '';
|
let v = this.serialIn.shift() || "";
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialOutBuffer: string = '';
|
kill() {
|
||||||
|
super.kill();
|
||||||
|
AudioContextManager.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
serialOutBuffer: string = "";
|
||||||
writeSerial(s: string) {
|
writeSerial(s: string) {
|
||||||
for (let i = 0; i < s.length; ++i) {
|
for (let i = 0; i < s.length; ++i) {
|
||||||
let c = s[i];
|
let c = s[i];
|
||||||
this.serialOutBuffer += c;
|
this.serialOutBuffer += c;
|
||||||
if (c == '\n') {
|
if (c == "\n") {
|
||||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||||
type: 'serial',
|
type: "serial",
|
||||||
data: this.serialOutBuffer,
|
data: this.serialOutBuffer,
|
||||||
id: runtime.id
|
id: runtime.id
|
||||||
})
|
})
|
||||||
this.serialOutBuffer = ''
|
this.serialOutBuffer = ""
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||