Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e581eaa41 | ||
|
|
4252829a9e | ||
|
|
d4475645f4 | ||
|
|
44beec4661 | ||
|
|
bd1f5a2b75 | ||
|
|
2cd3bca8db | ||
|
|
7d751fa322 | ||
|
|
3ee7c7f0b2 | ||
|
|
4ebeee7cf2 | ||
|
|
ea3cf55670 | ||
|
|
7c1b761964 | ||
|
|
b0fddd7e72 | ||
|
|
5a1321c711 | ||
|
|
e448512a3a | ||
|
|
f67e79ff3e | ||
|
|
ae6108e4fe | ||
|
|
0fac3cac8f | ||
|
|
a67d9ef1ab |
@@ -3,7 +3,7 @@
|
||||
### @description Language constructs for the Block editor.
|
||||
|
||||
Blocks snap into each other to define the program that your @boardname@ will run.
|
||||
Blocks can be event (buttons, shake, ...) or need to be snapped into an event to run.
|
||||
Blocks can be event (buttons, shake, ...) or need to be snapped into an event to run.
|
||||
The [on-start](/blocks/on-start) event runs first.
|
||||
|
||||
```namespaces
|
||||
@@ -15,4 +15,4 @@ Math.random(5);
|
||||
|
||||
## See Also
|
||||
|
||||
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables), [on-start](/blocks/on-start)
|
||||
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables), [on-start](/blocks/on-start), [javascript blocks](/blocks/javascript-blocks)
|
||||
65
docs/blocks/javascript-blocks.md
Normal file
65
docs/blocks/javascript-blocks.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# JavaScript Block
|
||||
|
||||
JavaScript is a very powerful language; so powerful that some concepts in
|
||||
JavaScript can't be shown using blocks. When PXT encounters a piece of code
|
||||
that can't be converted into blocks, it instead creates a grey JavaScript block
|
||||
to preserve it. These blocks get converted right back into the original
|
||||
JavaScript when you switch back to the text editor.
|
||||
|
||||
```blocks
|
||||
for (let index = 0; index <= 5; index++) {
|
||||
basic.showNumber(fibonacci(index))
|
||||
}
|
||||
|
||||
function fibonacci(n: number): number {
|
||||
if (n === 0 || n === 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
```
|
||||
|
||||
The code in JavaScript blocks cannot be edited, but the blocks
|
||||
themselves can be moved, copied, pasted, and deleted just like any
|
||||
other block.
|
||||
|
||||
|
||||
## How do I get my JavaScript code to convert without any grey blocks?
|
||||
|
||||
The easiest way to write code that will convert cleanly back to blocks
|
||||
is to write the code using blocks and convert it to JavaScript. Many blocks
|
||||
have a very specifc structure to their JavaScript that must be
|
||||
followed in order to have them convert properly. If you have a
|
||||
piece of your code that does not convert, try looking at the block
|
||||
you were expecting and the JavaScript it produces.
|
||||
|
||||
For example, a for-loop must have this structure to convert to a block:
|
||||
|
||||
```typescript
|
||||
for (let x = 0; x <= 5; x++) {
|
||||
}
|
||||
```
|
||||
|
||||
The following examples can't be represented by the blocks:
|
||||
|
||||
```typescript
|
||||
// Condition must be either < or <= with a variable on the left side
|
||||
for (let x = 0; x > -1; x++) {
|
||||
}
|
||||
|
||||
// The variable in the condition and incrementor must be the declared variable
|
||||
for (let x = 0; x <= 5; y++) {
|
||||
}
|
||||
|
||||
// The declared variable must be initialized to 0
|
||||
for (let x = 2; x <= 5; x++) {
|
||||
}
|
||||
|
||||
// All three parts of the for-loop must be present
|
||||
for (;;) {
|
||||
}
|
||||
```
|
||||
|
||||
Try to match the JavaScript of the desired block as closely as
|
||||
possible.
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v0.9.23"
|
||||
"appref": "v0.9.35"
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
# Play Built-in Melody
|
||||
# Begin Melody
|
||||
|
||||
Play a built in musical melody through pin ``P0`` of the @boardname@.
|
||||
Begin playing a musical melody through pin ``P0`` of the @boardname@.
|
||||
|
||||
## Simulator
|
||||
|
||||
This function only works on the @boardname@ and in some browsers.
|
||||
|
||||
```sig
|
||||
music.playBuiltinMelody(Melodies.Entertainer)
|
||||
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``melody`` is the kind of built-in melody you want to play
|
||||
* ``melody`` is the array representation of a melody you wish to play
|
||||
|
||||
## Example
|
||||
|
||||
This example plays the ``Entertainer`` melody.
|
||||
This example plays the ``Entertainer`` built-in melody.
|
||||
|
||||
```blocks
|
||||
music.playBuiltinMelody(Melodies.Entertainer)
|
||||
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
|
||||
```
|
||||
|
||||
### See also
|
||||
10
libs/core/dal.d.ts
vendored
10
libs/core/dal.d.ts
vendored
@@ -81,6 +81,9 @@ declare const enum DAL {
|
||||
MICROBIT_BLE_MAXIMUM_BONDS = 4,
|
||||
MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL = 400,
|
||||
MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER = 0xF0,
|
||||
MICROBIT_BLE_STATUS_STORE_SYSATTR = 0x02,
|
||||
MICROBIT_BLE_STATUS_DISCONNECT = 0x04,
|
||||
MICROBIT_BLE_DISCONNECT_AFTER_PAIRING_DELAY = 500,
|
||||
// built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitButtonService.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitDFUService.h
|
||||
MICROBIT_DFU_OPCODE_START_DFU = 1,
|
||||
@@ -191,10 +194,7 @@ declare const enum DAL {
|
||||
MICROBIT_SERIAL_EVT_TX_EMPTY = 2,
|
||||
MICROBIT_UART_S_EVT_TX_EMPTY = 3,
|
||||
// built/yt/yotta_modules/microbit-dal/inc/drivers/DynamicPwm.h
|
||||
NO_PWMS = 3,
|
||||
MICROBIT_DEFAULT_PWM_PERIOD = 20000,
|
||||
PWM_PERSISTENCE_TRANSIENT = 1,
|
||||
PWM_PERSISTENCE_PERSISTENT = 2,
|
||||
// built/yt/yotta_modules/microbit-dal/inc/drivers/MicroBitAccelerometer.h
|
||||
MICROBIT_ACCEL_PITCH_ROLL_VALID = 0x02,
|
||||
MICROBIT_ACCEL_ADDED_TO_IDLE = 0x04,
|
||||
@@ -375,8 +375,8 @@ declare const enum DAL {
|
||||
MICROBIT_PIN_EVT_FALL = 3,
|
||||
MICROBIT_PIN_EVT_PULSE_HI = 4,
|
||||
MICROBIT_PIN_EVT_PULSE_LO = 5,
|
||||
PIN_CAPABILITY_DIGITAL = 0x01,
|
||||
PIN_CAPABILITY_ANALOG = 0x02,
|
||||
PIN_CAPABILITY_DIGITAL_IN = 0x01,
|
||||
PIN_CAPABILITY_DIGITAL_OUT = 0x02,
|
||||
// built/yt/yotta_modules/microbit-dal/inc/drivers/MicroBitRadio.h
|
||||
MICROBIT_RADIO_STATUS_INITIALISED = 0x0001,
|
||||
MICROBIT_RADIO_BASE_ADDRESS = 0x75626974,
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace music {
|
||||
* @param melody the melody array to play, eg: ['g5:1']
|
||||
* @param options melody options, once / forever, in the foreground / background
|
||||
*/
|
||||
//% help=music/start-melody weight=60
|
||||
//% help=music/begin-melody weight=60
|
||||
//% blockId=device_start_melody block="start|melody %melody=device_builtin_melody| repeating %options"
|
||||
//% parts="headphone"
|
||||
export function beginMelody(melodyArray: string[], options: MelodyOptions = MelodyOptions.Once) {
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace radio {
|
||||
* @ param id the group id between ``0`` and ``255``, 1 eg
|
||||
*/
|
||||
//% help=radio/set-group
|
||||
//% weight=10 blockGap=8 advanced=true
|
||||
//% weight=10 blockGap=8
|
||||
//% blockId=radio_set_group block="radio set group %ID"
|
||||
void setGroup(int id) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
2
libs/radio/shims.d.ts
vendored
2
libs/radio/shims.d.ts
vendored
@@ -98,7 +98,7 @@ declare namespace radio {
|
||||
* @ param id the group id between ``0`` and ``255``, 1 eg
|
||||
*/
|
||||
//% help=radio/set-group
|
||||
//% weight=10 blockGap=8 advanced=true
|
||||
//% weight=10 blockGap=8
|
||||
//% blockId=radio_set_group block="radio set group %ID" shim=radio::setGroup
|
||||
function setGroup(id: number): void;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.9.27",
|
||||
"version": "0.9.36",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@@ -36,6 +36,6 @@
|
||||
"semantic-ui-less": "^2.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.11.51"
|
||||
"pxt-core": "0.11.59"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
"yottaTarget": "bbc-microbit-classic-gcc",
|
||||
"yottaCorePackage": "microbit",
|
||||
"githubCorePackage": "lancaster-university/microbit",
|
||||
"gittag": "v2.0.0-rc7",
|
||||
"gittag": "v2.0.0-rc8",
|
||||
"serviceId": "microbit"
|
||||
},
|
||||
"serial": {
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace pxsim {
|
||||
neopixelState: NeoPixelState;
|
||||
fileSystem: FileSystemState;
|
||||
|
||||
// visual
|
||||
view: SVGElement;
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
@@ -123,10 +126,14 @@ namespace pxsim {
|
||||
}), opts);
|
||||
|
||||
document.body.innerHTML = ""; // clear children
|
||||
document.body.appendChild(viewHost.getView());
|
||||
document.body.appendChild(this.view = viewHost.getView());
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
screenshot(): string {
|
||||
return svg.toDataUri(new XMLSerializer().serializeToString(this.view));
|
||||
}
|
||||
}
|
||||
|
||||
export function initRuntimeWithDalBoard() {
|
||||
|
||||
Reference in New Issue
Block a user