Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
532abadb6b | |||
eea179e07c | |||
f94015803f | |||
f085253306 | |||
6de2f22542 | |||
3051e09bcf | |||
bd835a8a6e | |||
f75a034a3f | |||
71b3b6bb22 | |||
b868bd1e09 | |||
02e48f196c | |||
742eb7ea2f | |||
f1904143b6 | |||
e621252f3b | |||
3633d39f57 | |||
21bbf8fc86 | |||
dd5124f660 | |||
966ad1f503 | |||
d94f394d24 | |||
40ddd896cf | |||
5a8815c4fc |
@ -24,24 +24,23 @@ npm install
|
|||||||
|
|
||||||
### Running
|
### Running
|
||||||
|
|
||||||
Run this command to open a local web server:
|
Run this command to open a local web server (add ``sudo`` for Mac/Linux shells)
|
||||||
```
|
```
|
||||||
pxt serve
|
pxt serve
|
||||||
```
|
```
|
||||||
If the local server opens in the wrong browser, make sure to copy the URL containing the local token.
|
If the local server opens in the wrong browser, make sure to copy the URL containing the local token.
|
||||||
Otherwise, the editor will not be able to load the projects.
|
Otherwise, the editor will not be able to load the projects.
|
||||||
|
|
||||||
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag:
|
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag (add ``sudo`` for Mac/Linux shells):
|
||||||
```
|
```
|
||||||
pxt serve -yt
|
pxt serve -yt
|
||||||
```
|
```
|
||||||
|
|
||||||
To make sure you're running the latest tools, run
|
To make sure you're running the latest tools, run (add ``sudo`` for Mac/Linux shells)
|
||||||
```
|
```
|
||||||
npm update
|
pxt update
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
|
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
|
||||||
|
|
||||||
## Universal Windows App
|
## Universal Windows App
|
||||||
|
@ -7,8 +7,6 @@ Are you ready to build cool BBC micro:bit programs?
|
|||||||
Here are some challenges for you. Unscramble the blocks in the editor
|
Here are some challenges for you. Unscramble the blocks in the editor
|
||||||
to make real programs that work!
|
to make real programs that work!
|
||||||
|
|
||||||
[OPEN EDITOR](/#follow:getting-started)
|
|
||||||
|
|
||||||
## ~
|
## ~
|
||||||
|
|
||||||
### Happy face
|
### Happy face
|
||||||
@ -197,7 +195,7 @@ metal stripe at the bottom of the micro:bit board.) For example, hold
|
|||||||
the ``GND`` button with one hand and touch the ``0`` pin (called
|
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.
|
``P0``) with your other hand to tell the micro:bit you're pressing it.
|
||||||
|
|
||||||
Unscramble the blocks in the editor to show a heart when you press
|
Unscramble the blocks in the editor to show a heart when you touch
|
||||||
pin ``P0``.
|
pin ``P0``.
|
||||||
|
|
||||||
```shuffle
|
```shuffle
|
||||||
@ -214,19 +212,96 @@ Click **Compile** to move your program to the BBC micro:bit!
|
|||||||
|
|
||||||
## ~hint
|
## ~hint
|
||||||
|
|
||||||
Try this experiment: find a friend and hold hands together. Press the ``GND`` button
|
Try this experiment: find a friend and hold hands. Touch the ``GND``
|
||||||
while your friend pressed the ``P0`` button. You should see the heart! The electric current is going through your bodies and accross your handshake
|
pin while your friend presses the ``P0`` pin. You should see the
|
||||||
to make it happen!
|
heart! The electric current is going through your bodies and across
|
||||||
|
your handshake to make it happen!
|
||||||
|
|
||||||
## ~
|
## ~
|
||||||
|
|
||||||
|
## The amazing coin flipper
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Are you trying to choose whether to play soccer or go to the movies
|
||||||
|
instead, or which toppings to have on your pizza? Build a coin
|
||||||
|
flipping machine with the BBC micro:bit to choose for you!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
Here are the blocks to make your coin flipper. When you press button
|
||||||
|
`B`, the coin flipper will show either `H` for heads or `T` for tails
|
||||||
|
on the LED screen.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.B, () => {
|
||||||
|
if (Math.randomBoolean()) {
|
||||||
|
basic.showString("H");
|
||||||
|
} else {
|
||||||
|
basic.showString("T");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
The ``pick random true or false`` block randomly tells the ``if``
|
||||||
|
block `true` or `false`. If the ``pick`` block picked `true`, the
|
||||||
|
``if`` block shows the letter `H`. Otherwise, it shows the letter `T`.
|
||||||
|
|
||||||
|
That's it!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### Keeping score
|
||||||
|
|
||||||
|
#### ~avatar
|
||||||
|
|
||||||
|
To keep track out of how many guesses you've won,
|
||||||
|
add these blocks to your coin flipper:
|
||||||
|
|
||||||
|
#### ~
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1);
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.AB, () => {
|
||||||
|
basic.showNumber(game.score());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
These blocks mean that if you press button `A`, you will add `1` to
|
||||||
|
your score, and if you press `A` and `B` together, the micro:bit will
|
||||||
|
show your score.
|
||||||
|
|
||||||
|
When you're done, your coin flipping program should look like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.B, () => {
|
||||||
|
if (Math.randomBoolean()) {
|
||||||
|
basic.showString("H");
|
||||||
|
} else {
|
||||||
|
basic.showString("T");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1);
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.AB, () => {
|
||||||
|
basic.showNumber(game.score());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Flip until your thumbs get tired!
|
||||||
|
|
||||||
## Let's play Rock Paper Scissors!
|
## Let's play Rock Paper Scissors!
|
||||||
|
|
||||||
### ~avatar avatar
|
### ~avatar avatar
|
||||||
|
|
||||||
Build a Rock Paper Scissors game with the BBC micro:bit!
|
Build a Rock Paper Scissors game with the BBC micro:bit! You can play
|
||||||
You can play the game with a friend who has it on a micro:bit.
|
the game with a friend who has it on a micro:bit. You can also play
|
||||||
You can also play it with friends who are just using their hands.
|
it with friends who are just using their hands. (The game is built
|
||||||
|
like a coin flipper, but with three choices instead of two.)
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# Change Tempo By
|
# Change Tempo By
|
||||||
|
|
||||||
Change the tempo by the specified amount
|
Makes the [tempo](/reference/music/tempo) (speed of a piece of music)
|
||||||
|
faster or slower by the amount you say.
|
||||||
|
|
||||||
## Simulator
|
## 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
|
```sig
|
||||||
music.changeTempoBy(20)
|
music.changeTempoBy(20)
|
||||||
@ -12,7 +13,21 @@ music.changeTempoBy(20)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `bpm` : [Number](/reference/types/number) - change the tempo by beats per minute
|
* a [number](/reference/types/number) that says how much to change the bpm (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
This program makes the music faster by 12 bpm.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
music.changeTempoBy(12)
|
||||||
|
```
|
||||||
|
|
||||||
|
This program makes the music _slower_ by 12 bpm.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
music.changeTempoBy(-12)
|
||||||
|
```
|
||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# Rest
|
# Rest
|
||||||
|
|
||||||
Rests (plays nothing) for a specified time through pin PO.
|
Rest (play no sound) through pin `PO` for the amount of time you say.
|
||||||
|
|
||||||
## Simulator
|
## 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
|
```sig
|
||||||
music.rest(400)
|
music.rest(400)
|
||||||
@ -12,7 +12,7 @@ music.rest(400)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `ms`: [Number](/reference/types/number) - the duration of the rest (milliseconds)
|
* a [number](/reference/types/number) saying how many milliseconds the micro:bit should rest. One second is 1000 milliseconds.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
# Set Tempo
|
# Set Tempo
|
||||||
|
|
||||||
Sets the tempo to the specified amount
|
Makes the tempo (speed of a piece of music) as fast or slow as you say.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
music.setTempo(60)
|
music.setTempo(60)
|
||||||
```
|
```
|
||||||
|
## Simulator
|
||||||
|
|
||||||
|
This function only works on the micro:bit and in some browsers.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* Returns : [Number](/reference/types/number) - sets the tempo in beats per minute
|
* a [number](/reference/types/number) that means the bpm you want (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
|
||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``camera`` command to the parent device.
|
* Sends a ``camera`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=30 help=devices/tell-camera-to
|
//% weight=30 help=devices/tell-camera-to
|
||||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
||||||
@ -139,7 +139,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``remote control`` command to the parent device.
|
* Sends a ``remote control`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=29 help=devices/tell-remote-control-to
|
//% weight=29 help=devices/tell-remote-control-to
|
||||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
||||||
@ -149,7 +149,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ``alert`` command to the parent device.
|
* Sends an ``alert`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=27 help=devices/raise-alert-to
|
//% weight=27 help=devices/raise-alert-to
|
||||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
||||||
@ -159,19 +159,19 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a particular event.
|
* Registers code to run when the device notifies about a particular event.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
* @param body TODO
|
* @param body code handler when event is triggered
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-notified weight=26
|
//% help=devices/on-notified weight=26
|
||||||
//% blockId=devices_device_info_event block="on notified" icon="\uf10a"
|
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a"
|
||||||
void onNotified(MesDeviceInfo event, Action body) {
|
void onNotified(MesDeviceInfo event, Action body) {
|
||||||
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
|
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||||
* @param name TODO
|
* @param name button name
|
||||||
* @param body TODO
|
* @param body code to run when button is pressed
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-gamepad-button weight=40
|
//% help=devices/on-gamepad-button weight=40
|
||||||
//% weight=25
|
//% weight=25
|
||||||
@ -188,7 +188,7 @@ namespace devices {
|
|||||||
static void initSignalStrength() {
|
static void initSignalStrength() {
|
||||||
if (_signalStrength < 0) {
|
if (_signalStrength < 0) {
|
||||||
_signalStrength = 0;
|
_signalStrength = 0;
|
||||||
uBit.MessageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);
|
uBit.messageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,5 +20,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"installedVersion": "zakvul"
|
"installedVersion": "ljipgq"
|
||||||
}
|
}
|
||||||
|
16
libs/microbit-devices/shims.d.ts
vendored
16
libs/microbit-devices/shims.d.ts
vendored
@ -7,7 +7,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``camera`` command to the parent device.
|
* Sends a ``camera`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=30 help=devices/tell-camera-to
|
//% weight=30 help=devices/tell-camera-to
|
||||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
||||||
@ -15,7 +15,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``remote control`` command to the parent device.
|
* Sends a ``remote control`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=29 help=devices/tell-remote-control-to
|
//% weight=29 help=devices/tell-remote-control-to
|
||||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
||||||
@ -23,7 +23,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ``alert`` command to the parent device.
|
* Sends an ``alert`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=27 help=devices/raise-alert-to
|
//% weight=27 help=devices/raise-alert-to
|
||||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
||||||
@ -31,17 +31,17 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a particular event.
|
* Registers code to run when the device notifies about a particular event.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
* @param body TODO
|
* @param body code handler when event is triggered
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-notified weight=26
|
//% help=devices/on-notified weight=26
|
||||||
//% blockId=devices_device_info_event block="on notified" icon="\uf10a" shim=devices::onNotified
|
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a" shim=devices::onNotified
|
||||||
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||||
* @param name TODO
|
* @param name button name
|
||||||
* @param body TODO
|
* @param body code to run when button is pressed
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-gamepad-button weight=40
|
//% help=devices/on-gamepad-button weight=40
|
||||||
//% weight=25
|
//% weight=25
|
||||||
|
@ -9,9 +9,13 @@
|
|||||||
"testFiles": [
|
"testFiles": [
|
||||||
"neotest.ts"
|
"neotest.ts"
|
||||||
],
|
],
|
||||||
"microbit": {
|
"yotta": {
|
||||||
"config": {
|
"config": {
|
||||||
"MICROBIT_BLE_ENABLED": "0"
|
"microbit-dal": {
|
||||||
|
"bluetooth": {
|
||||||
|
"enabled": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"public": true,
|
"public": true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.149",
|
"version": "0.2.155",
|
||||||
"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.162"
|
"pxt-core": "0.2.167"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
"corepkg": "microbit",
|
"corepkg": "microbit",
|
||||||
"bundleddirs": [
|
"bundleddirs": [
|
||||||
"libs/microbit",
|
"libs/microbit",
|
||||||
"libs/microbit-radio"
|
"libs/microbit-radio",
|
||||||
|
"libs/microbit-devices",
|
||||||
|
"libs/neopixel"
|
||||||
],
|
],
|
||||||
"cloud": {
|
"cloud": {
|
||||||
"workspace": false,
|
"workspace": false,
|
||||||
@ -105,10 +107,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Lessons",
|
"name": "Lessons",
|
||||||
"path": "/lessons"
|
"path": "/lessons"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Device",
|
|
||||||
"path": "/device"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sideDoc": "getting-started"
|
"sideDoc": "getting-started"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>microbit simulator</title>
|
<title>BBC micro:bit simulator</title>
|
||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -13,11 +13,10 @@ html {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
width:100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
-webkit-overflow-scrolling: touch;
|
|
||||||
overflow-scrolling: touch;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="/cdn/bluebird.min.js"></script>
|
<script src="/cdn/bluebird.min.js"></script>
|
||||||
|
Reference in New Issue
Block a user