Compare commits

..

16 Commits

12 changed files with 145 additions and 50 deletions

View File

@ -24,24 +24,23 @@ npm install
### 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
```
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.
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
```
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
## Universal Windows App

View File

@ -195,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
``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``.
```shuffle
@ -212,19 +212,96 @@ Click **Compile** to move your program to the BBC micro:bit!
## ~hint
Try this experiment: find a friend and hold hands together. Press the ``GND`` button
while your friend pressed the ``P0`` button. You should see the heart! The electric current is going through your bodies and accross your handshake
to make it happen!
Try this experiment: find a friend and hold hands. Touch the ``GND``
pin while your friend presses the ``P0`` pin. You should see the
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!
### ~avatar avatar
Build a Rock Paper Scissors game with the BBC micro:bit!
You can play the game with a friend who has it on a micro:bit.
You can also play it with friends who are just using their hands.
Build a Rock Paper Scissors game with the BBC micro:bit! You can play
the game with a friend who has it on a micro:bit. You can also play
it with friends who are just using their hands. (The game is built
like a coin flipper, but with three choices instead of two.)
### ~

View File

@ -1,10 +1,11 @@
# 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
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
music.changeTempoBy(20)
@ -12,7 +13,21 @@ music.changeTempoBy(20)
### 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

View File

@ -1,10 +1,10 @@
# 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
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
music.rest(400)
@ -12,7 +12,7 @@ music.rest(400)
### 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

View File

@ -1,14 +1,17 @@
# 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
music.setTempo(60)
```
## Simulator
This function only works on the micro:bit and in some browsers.
### 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

View File

@ -129,7 +129,7 @@ namespace devices {
/**
* Sends a ``camera`` command to the parent device.
* @param event TODO
* @param event event description
*/
//% weight=30 help=devices/tell-camera-to
//% 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.
* @param event TODO
* @param event event description
*/
//% weight=29 help=devices/tell-remote-control-to
//% 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.
* @param event TODO
* @param event event description
*/
//% weight=27 help=devices/raise-alert-to
//% 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.
* @param event TODO
* @param body TODO
* @param event event description
* @param body code handler when event is triggered
*/
//% 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) {
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
}
/**
* Register code to run when the micro:bit receives a command from the paired gamepad.
* @param name TODO
* @param body TODO
* @param name button name
* @param body code to run when button is pressed
*/
//% help=devices/on-gamepad-button weight=40
//% weight=25
@ -188,7 +188,7 @@ namespace devices {
static void initSignalStrength() {
if (_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);
}
}

View File

@ -20,5 +20,5 @@
}
}
},
"installedVersion": "zakvul"
"installedVersion": "ljipgq"
}

View File

@ -7,7 +7,7 @@ declare namespace devices {
/**
* Sends a ``camera`` command to the parent device.
* @param event TODO
* @param event event description
*/
//% weight=30 help=devices/tell-camera-to
//% 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.
* @param event TODO
* @param event event description
*/
//% 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
@ -23,7 +23,7 @@ declare namespace devices {
/**
* Sends an ``alert`` command to the parent device.
* @param event TODO
* @param event event description
*/
//% weight=27 help=devices/raise-alert-to
//% 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.
* @param event TODO
* @param body TODO
* @param event event description
* @param body code handler when event is triggered
*/
//% 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;
/**
* Register code to run when the micro:bit receives a command from the paired gamepad.
* @param name TODO
* @param body TODO
* @param name button name
* @param body code to run when button is pressed
*/
//% help=devices/on-gamepad-button weight=40
//% weight=25

View File

@ -9,9 +9,13 @@
"testFiles": [
"neotest.ts"
],
"microbit": {
"yotta": {
"config": {
"MICROBIT_BLE_ENABLED": "0"
"microbit-dal": {
"bluetooth": {
"enabled": 0
}
}
}
},
"public": true,

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.152",
"version": "0.2.155",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.163"
"pxt-core": "0.2.167"
}
}

View File

@ -5,7 +5,9 @@
"corepkg": "microbit",
"bundleddirs": [
"libs/microbit",
"libs/microbit-radio"
"libs/microbit-radio",
"libs/microbit-devices",
"libs/neopixel"
],
"cloud": {
"workspace": false,
@ -105,10 +107,6 @@
{
"name": "Lessons",
"path": "/lessons"
},
{
"name": "Device",
"path": "/device"
}
],
"sideDoc": "getting-started"

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>microbit simulator</title>
<title>BBC micro:bit simulator</title>
<style>
html {
height: 100%;
@ -13,11 +13,10 @@ html {
body {
height: 100%;
width:100%;
padding: 0;
overflow: hidden;
margin: 0;
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}
</style>
<script src="/cdn/bluebird.min.js"></script>