Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
9607183587 | |||
4cca961e52 | |||
c2a1668d55 | |||
7102eddc0b | |||
b34884fe00 | |||
e768a4dc97 | |||
8b1b1bb869 | |||
57deb1749f | |||
fb82b94f69 | |||
d321170da9 | |||
dff4f3adb3 | |||
5d8a1b69f6 | |||
0b0c2c9466 | |||
895a099ebf | |||
f7ed06108d | |||
0ffccdca85 | |||
9f5ebdfb78 | |||
9319f10430 | |||
c4787e1028 | |||
cb280af783 | |||
6e64e80c05 | |||
dde16fec14 |
23
README.md
23
README.md
@ -1,11 +1,11 @@
|
|||||||
# micro:bit target for PXT
|
# Calliope target for PXT
|
||||||
|
|
||||||
This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) using
|
This target allow to program a [Calliope](http://calliope.cc/) using
|
||||||
PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)).
|
PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)).
|
||||||
|
|
||||||
* [Try it live](https://codethemicrobit.com)
|
[](https://travis-ci.org/Microsoft/pxt-calliope)
|
||||||
|
|
||||||
[](https://travis-ci.org/Microsoft/pxt-microbit)
|

|
||||||
|
|
||||||
## Local server
|
## Local server
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ The following commands are a 1-time setup after synching the repo on your machin
|
|||||||
* if not yet installed, install [Node.js 4.4.5 or higher](https://nodejs.org/en/download/)
|
* if not yet installed, install [Node.js 4.4.5 or higher](https://nodejs.org/en/download/)
|
||||||
* [clone this repo](https://help.github.com/articles/cloning-a-repository/) to your computer and go in the project folder
|
* [clone this repo](https://help.github.com/articles/cloning-a-repository/) to your computer and go in the project folder
|
||||||
```
|
```
|
||||||
git clone https://github.com/microsoft/pxt-microbit
|
git clone https://github.com/microsoft/pxt-calliope
|
||||||
cd pxt-microbit
|
cd pxt-calliope
|
||||||
```
|
```
|
||||||
* install the PXT command line (add ``sudo`` for Mac/Linux shells).
|
* install the PXT command line (add ``sudo`` for Mac/Linux shells).
|
||||||
```
|
```
|
||||||
@ -32,14 +32,15 @@ npm install
|
|||||||
|
|
||||||
### Running
|
### Running
|
||||||
|
|
||||||
Run this command to open a local web server (add ``sudo`` for Mac/Linux shells)
|
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 (add ``sudo`` for Mac/Linux shells):
|
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag (add ``sudo`` for Mac/Linux shells). On Windows, you must be running
|
||||||
|
from the ``Run Yotta`` command prompt.
|
||||||
```
|
```
|
||||||
pxt serve -yt
|
pxt serve -yt
|
||||||
```
|
```
|
||||||
@ -53,11 +54,6 @@ 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
|
||||||
|
|
||||||
### Building
|
|
||||||
|
|
||||||
* Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed.
|
|
||||||
* open the ``win10/app.sln`` solution and launch the ``codethemicrobit`` project.
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
The build automatically runs the following:
|
The build automatically runs the following:
|
||||||
@ -66,7 +62,6 @@ The build automatically runs the following:
|
|||||||
* `pxt run` in `libs/lang-test*` - this will run the test in command line runner;
|
* `pxt run` in `libs/lang-test*` - this will run the test in command line runner;
|
||||||
there is a number of asserts in both of these
|
there is a number of asserts in both of these
|
||||||
* `pxt testdir` in `tests` - this makes sure all the files compile and generates .hex files
|
* `pxt testdir` in `tests` - this makes sure all the files compile and generates .hex files
|
||||||
* run the TD->TS converter on a number of test scripts from `microbit.co.uk` and make sure the results compile
|
|
||||||
|
|
||||||
To test something on the device:
|
To test something on the device:
|
||||||
|
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||||
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
||||||
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
|
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
|
||||||
if (pxtConfig) mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
|
if (typeof pxtConfig !== "undefined") mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||||
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
||||||
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
|
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
|
||||||
if (pxtConfig) mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
|
if (typeof pxtConfig !== "undefined") mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
|
||||||
</script>
|
</script>
|
||||||
|
@ -10,6 +10,10 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
music.playTone(0, 0);
|
music.playTone(0, 0);
|
||||||
led.plot(0, 0);
|
led.plot(0, 0);
|
||||||
radio.sendNumber(0);
|
radio.sendNumber(0);
|
||||||
|
```
|
||||||
|
## Advanced
|
||||||
|
|
||||||
|
```namespaces
|
||||||
game.addScore(1);
|
game.addScore(1);
|
||||||
images.createImage(`
|
images.createImage(`
|
||||||
. . . . .
|
. . . . .
|
||||||
@ -24,7 +28,8 @@ control.inBackground(() => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
## Advanced
|
|
||||||
|
## Bluetooth
|
||||||
|
|
||||||
```namespaces
|
```namespaces
|
||||||
devices.tellCameraTo(MesCameraEvent.TakePhoto);
|
devices.tellCameraTo(MesCameraEvent.TakePhoto);
|
||||||
|
@ -6,6 +6,24 @@
|
|||||||
*/
|
*/
|
||||||
//% color=#0078D7 weight=100
|
//% color=#0078D7 weight=100
|
||||||
namespace basic {
|
namespace basic {
|
||||||
|
/**
|
||||||
|
* Sets the color on the build-in LED. Set to 0 to turn off.
|
||||||
|
*/
|
||||||
|
//% blockId=device_set_led_color block="set led to %color=color_id" icon="\uf00a"
|
||||||
|
//% weight=50
|
||||||
|
void setLedColor(int color) {
|
||||||
|
if (!color) {
|
||||||
|
uBit.rgb.off();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w = (color >> 24) & 0xFF;
|
||||||
|
int r = (color >> 16) & 0xFF;
|
||||||
|
int g = (color >> 8) & 0xFF;
|
||||||
|
int b = (color) & 0xFF;
|
||||||
|
|
||||||
|
uBit.rgb.setColour(r,g,b,w);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.
|
* Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.
|
||||||
|
@ -4,31 +4,31 @@
|
|||||||
enum Colors {
|
enum Colors {
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=red
|
//% block=red
|
||||||
Red = 0xFF0000,
|
Red = 0x00FF0000,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=orange
|
//% block=orange
|
||||||
Orange = 0xFFA500,
|
Orange = 0x00FFA500,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=yellow
|
//% block=yellow
|
||||||
Yellow = 0xFFFF00,
|
Yellow = 0x00FFFF00,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=green
|
//% block=green
|
||||||
Green = 0x00FF00,
|
Green = 0x0000FF00,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=blue
|
//% block=blue
|
||||||
Blue = 0x0000FF,
|
Blue = 0x000000FF,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=indigo
|
//% block=indigo
|
||||||
Indigo = 0x4b0082,
|
Indigo = 0x004b0082,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=violet
|
//% block=violet
|
||||||
Violet = 0x8a2be2,
|
Violet = 0x008a2be2,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=purple
|
//% block=purple
|
||||||
Purple = 0xFF00FF,
|
Purple = 0x00FF00FF,
|
||||||
//% blockIdentity=basic.color
|
//% blockIdentity=basic.color
|
||||||
//% block=white
|
//% block=white
|
||||||
White = 0xFFFFFF
|
White = 0xFF00000
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,16 +36,6 @@ enum Colors {
|
|||||||
*/
|
*/
|
||||||
//% color=#0078D7 weight=100
|
//% color=#0078D7 weight=100
|
||||||
namespace basic {
|
namespace basic {
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the color on the build-in LED
|
|
||||||
*/
|
|
||||||
//% blockId=device_set_led_color block="set led to %color=color_id" icon="\uf00a"
|
|
||||||
//% weight=50
|
|
||||||
export function setLedColor(color: number) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the color name to a number
|
* Converts the color name to a number
|
||||||
*/
|
*/
|
||||||
@ -53,4 +43,17 @@ namespace basic {
|
|||||||
export function color(c: Colors): number {
|
export function color(c: Colors): number {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts red, green, blue channels into a RGB color
|
||||||
|
* @param red value of the red channel between 0 and 255. eg: 255
|
||||||
|
* @param green value of the green channel between 0 and 255. eg: 255
|
||||||
|
* @param blue value of the blue channel between 0 and 255. eg: 255
|
||||||
|
* @param white value of the white channel between 0 and 255. eg: 0
|
||||||
|
*/
|
||||||
|
//% weight=1
|
||||||
|
//% blockId="core_rgb" block="red %red|green %green|blue %blue|white %white"
|
||||||
|
export function rgbw(red: number, green: number, blue: number, white:number): number {
|
||||||
|
return ((white & 0xFF) << 24) | ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | (blue & 0xFF);
|
||||||
|
}
|
||||||
}
|
}
|
@ -110,6 +110,7 @@ enum EventBusValue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//% weight=1 color="#333333"
|
//% weight=1 color="#333333"
|
||||||
|
//% advanced=true
|
||||||
namespace control {
|
namespace control {
|
||||||
void fiberDone(void *a)
|
void fiberDone(void *a)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* Runtime and event utilities.
|
* Runtime and event utilities.
|
||||||
*/
|
*/
|
||||||
//% weight=1 color="#333333"
|
//% weight=1 color="#333333"
|
||||||
|
//% advanced=true
|
||||||
namespace control {
|
namespace control {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
6
libs/core/dal.d.ts
vendored
6
libs/core/dal.d.ts
vendored
@ -190,12 +190,6 @@ declare const enum DAL {
|
|||||||
MICROBIT_SERIAL_EVT_TX_EMPTY = 2,
|
MICROBIT_SERIAL_EVT_TX_EMPTY = 2,
|
||||||
MICROBIT_UART_S_EVT_TX_EMPTY = 3,
|
MICROBIT_UART_S_EVT_TX_EMPTY = 3,
|
||||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/CalliopeRGB.h
|
// built/yt/yotta_modules/microbit-dal/inc//drivers/CalliopeRGB.h
|
||||||
RGB_LED_DEFAULT_GREEN = 0,
|
|
||||||
RGB_LED_DEFAULT_RED = 0,
|
|
||||||
RGB_LED_DEFAULT_BLUE = 0,
|
|
||||||
RGB_LED_DEFAULT_WHITE = 0,
|
|
||||||
RGB_KEEP_VALUE = -1,
|
|
||||||
RGB_LED_MAX_INTENSITY = 50,
|
|
||||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/CalliopeSoundMotor.h
|
// built/yt/yotta_modules/microbit-dal/inc//drivers/CalliopeSoundMotor.h
|
||||||
CALLIOPE_SM_DEFAULT_DUTY_M = 50,
|
CALLIOPE_SM_DEFAULT_DUTY_M = 50,
|
||||||
CALLIOPE_SM_DEFAULT_DUTY_S = 100,
|
CALLIOPE_SM_DEFAULT_DUTY_S = 100,
|
||||||
|
2
libs/core/enums.d.ts
vendored
2
libs/core/enums.d.ts
vendored
@ -238,6 +238,8 @@ declare namespace control {
|
|||||||
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
|
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
|
||||||
}
|
}
|
||||||
declare namespace led {
|
declare namespace led {
|
||||||
|
}
|
||||||
|
declare namespace motors {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ enum LedSpriteProperty {
|
|||||||
* A single-LED sprite game engine
|
* A single-LED sprite game engine
|
||||||
*/
|
*/
|
||||||
//% color=#008272 weight=32
|
//% color=#008272 weight=32
|
||||||
|
//% advanced=true
|
||||||
namespace game {
|
namespace game {
|
||||||
let _score: number = 0;
|
let _score: number = 0;
|
||||||
let _life: number = 3;
|
let _life: number = 3;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Creation, manipulation and display of LED images.
|
* Creation, manipulation and display of LED images.
|
||||||
*/
|
*/
|
||||||
//% color=#5C2D91 weight=31
|
//% color=#5C2D91 weight=31
|
||||||
|
//% advanced=true
|
||||||
namespace images {
|
namespace images {
|
||||||
/**
|
/**
|
||||||
* Creates an image that fits on the LED screen.
|
* Creates an image that fits on the LED screen.
|
||||||
|
@ -159,6 +159,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/on-pin-released weight=6 blockGap=8
|
//% help=input/on-pin-released weight=6 blockGap=8
|
||||||
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
|
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
|
||||||
|
//% advanced=true
|
||||||
void onPinReleased(TouchPin name, Action body) {
|
void onPinReleased(TouchPin name, Action body) {
|
||||||
auto pin = getPin((int)name);
|
auto pin = getPin((int)name);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
@ -171,7 +172,7 @@ namespace input {
|
|||||||
/**
|
/**
|
||||||
* Get the button state (pressed or not) for ``A`` and ``B``.
|
* Get the button state (pressed or not) for ``A`` and ``B``.
|
||||||
*/
|
*/
|
||||||
//% help=input/button-is-pressed weight=57
|
//% help=input/button-is-pressed weight=60
|
||||||
//% block="button|%NAME|is pressed"
|
//% block="button|%NAME|is pressed"
|
||||||
//% blockId=device_get_button2
|
//% blockId=device_get_button2
|
||||||
//% icon="\uf192" blockGap=8
|
//% icon="\uf192" blockGap=8
|
||||||
@ -190,7 +191,7 @@ namespace input {
|
|||||||
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
|
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
|
||||||
* @param name pin used to detect the touch
|
* @param name pin used to detect the touch
|
||||||
*/
|
*/
|
||||||
//% help=input/pin-is-pressed weight=56
|
//% help=input/pin-is-pressed weight=58
|
||||||
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
|
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
bool pinIsPressed(TouchPin name) {
|
bool pinIsPressed(TouchPin name) {
|
||||||
@ -198,6 +199,40 @@ namespace input {
|
|||||||
return pin && pin->isTouched();
|
return pin && pin->isTouched();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getAccelerationStrength() {
|
||||||
|
double x = uBit.accelerometer.getX();
|
||||||
|
double y = uBit.accelerometer.getY();
|
||||||
|
double z = uBit.accelerometer.getZ();
|
||||||
|
return (int)sqrt(x*x+y*y+z*z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
|
||||||
|
* @param dimension TODO
|
||||||
|
*/
|
||||||
|
//% help=input/acceleration weight=58 icon="\uf135"
|
||||||
|
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
||||||
|
//% parts="accelerometer"
|
||||||
|
int acceleration(Dimension dimension) {
|
||||||
|
switch (dimension) {
|
||||||
|
case Dimension::X: return uBit.accelerometer.getX();
|
||||||
|
case Dimension::Y: return uBit.accelerometer.getY();
|
||||||
|
case Dimension::Z: return uBit.accelerometer.getZ();
|
||||||
|
case Dimension::Strength: return getAccelerationStrength();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
||||||
|
*/
|
||||||
|
//% help=input/light-level weight=57
|
||||||
|
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
||||||
|
//% parts="ledmatrix"
|
||||||
|
int lightLevel() {
|
||||||
|
return uBit.display.readLightLevel();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current compass heading in degrees.
|
* Get the current compass heading in degrees.
|
||||||
*/
|
*/
|
||||||
@ -221,48 +256,13 @@ namespace input {
|
|||||||
return uBit.thermometer.getTemperature();
|
return uBit.thermometer.getTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getAccelerationStrength() {
|
|
||||||
double x = uBit.accelerometer.getX();
|
|
||||||
double y = uBit.accelerometer.getY();
|
|
||||||
double z = uBit.accelerometer.getZ();
|
|
||||||
return (int)sqrt(x*x+y*y+z*z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
|
|
||||||
* @param dimension TODO
|
|
||||||
*/
|
|
||||||
//% help=input/acceleration weight=54 icon="\uf135"
|
|
||||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
|
||||||
//% parts="accelerometer"
|
|
||||||
int acceleration(Dimension dimension) {
|
|
||||||
switch (dimension) {
|
|
||||||
case Dimension::X: return uBit.accelerometer.getX();
|
|
||||||
case Dimension::Y: return uBit.accelerometer.getY();
|
|
||||||
case Dimension::Z: return uBit.accelerometer.getZ();
|
|
||||||
case Dimension::Strength: return getAccelerationStrength();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
|
||||||
*/
|
|
||||||
//% help=input/light-level weight=53
|
|
||||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
|
||||||
//% parts="ledmatrix"
|
|
||||||
int lightLevel() {
|
|
||||||
return uBit.display.readLightLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.
|
* The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.
|
||||||
* @param kind TODO
|
* @param kind TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/rotation weight=52
|
//% help=input/rotation weight=52
|
||||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
||||||
//% parts="accelerometer"
|
//% parts="accelerometer" advanced=true
|
||||||
int rotation(Rotation kind) {
|
int rotation(Rotation kind) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case Rotation::Pitch: return uBit.accelerometer.getPitch();
|
case Rotation::Pitch: return uBit.accelerometer.getPitch();
|
||||||
@ -278,6 +278,7 @@ namespace input {
|
|||||||
//% help=input/magnetic-force weight=51
|
//% help=input/magnetic-force weight=51
|
||||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
||||||
//% parts="compass"
|
//% parts="compass"
|
||||||
|
//% advanced=true
|
||||||
int magneticForce(Dimension dimension) {
|
int magneticForce(Dimension dimension) {
|
||||||
if (!uBit.compass.isCalibrated())
|
if (!uBit.compass.isCalibrated())
|
||||||
uBit.compass.calibrate();
|
uBit.compass.calibrate();
|
||||||
@ -296,6 +297,7 @@ namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/running-time weight=50
|
//% help=input/running-time weight=50
|
||||||
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
|
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
|
||||||
|
//% advanced=true
|
||||||
int runningTime() {
|
int runningTime() {
|
||||||
return system_timer_current_time();
|
return system_timer_current_time();
|
||||||
}
|
}
|
||||||
@ -314,6 +316,7 @@ namespace input {
|
|||||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
||||||
//% weight=5
|
//% weight=5
|
||||||
//% parts="accelerometer"
|
//% parts="accelerometer"
|
||||||
|
//% advanced=true
|
||||||
void setAccelerometerRange(AcceleratorRange range) {
|
void setAccelerometerRange(AcceleratorRange range) {
|
||||||
uBit.accelerometer.setRange((int)range);
|
uBit.accelerometer.setRange((int)range);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ namespace led {
|
|||||||
//% help=led/brightness weight=60
|
//% help=led/brightness weight=60
|
||||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
||||||
//% parts="ledmatrix"
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true
|
||||||
int brightness() {
|
int brightness() {
|
||||||
return uBit.display.getBrightness();
|
return uBit.display.getBrightness();
|
||||||
}
|
}
|
||||||
@ -65,6 +66,7 @@ namespace led {
|
|||||||
//% help=led/set-brightness weight=59
|
//% help=led/set-brightness weight=59
|
||||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
||||||
//% parts="ledmatrix"
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true
|
||||||
void setBrightness(int value) {
|
void setBrightness(int value) {
|
||||||
uBit.display.setBrightness(value);
|
uBit.display.setBrightness(value);
|
||||||
}
|
}
|
||||||
@ -75,6 +77,7 @@ namespace led {
|
|||||||
//% weight=50 help=led/stop-animation
|
//% weight=50 help=led/stop-animation
|
||||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
||||||
//% parts="ledmatrix"
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true
|
||||||
void stopAnimation() {
|
void stopAnimation() {
|
||||||
uBit.display.stopAnimation();
|
uBit.display.stopAnimation();
|
||||||
}
|
}
|
||||||
|
17
libs/core/motors.cpp
Normal file
17
libs/core/motors.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "ksbit.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks to control the onboard motors
|
||||||
|
*/
|
||||||
|
//% weight=30
|
||||||
|
namespace motors {
|
||||||
|
/**
|
||||||
|
* Controls the power sent to a single motor
|
||||||
|
* @param power %percent of power sent to the motor. Negative power goes backward. eg: 50
|
||||||
|
*/
|
||||||
|
//% blockId=motor_on block="motor on at %percent|%"
|
||||||
|
//% parts=dcmotor
|
||||||
|
void motorOn(int power) {
|
||||||
|
uBit.soundmotor.Motor_On(power);
|
||||||
|
}
|
||||||
|
}
|
12
libs/core/parts/dcmotor.svg
Normal file
12
libs/core/parts/dcmotor.svg
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="488" height="836" viewBox="0 0 488 836">
|
||||||
|
<g transform="translate(0 -216.362)">
|
||||||
|
<rect width="34.286" height="122.532" x="226.365" y="929.711" fill="#ccc" ry="16.162"/>
|
||||||
|
<path fill="gray" d="M23.23 359.456A23.233 23.233 0 0 0 0 382.686v511.428a23.233 23.233 0 0 0 23.23 23.23h38.2v24.117a23.233 23.233 0 0 0 23.23 23.234h317.143a23.233 23.233 0 0 0 23.23-23.23v-24.118h38.197a23.233 23.233 0 0 0 23.23-23.23v-511.43a23.233 23.233 0 0 0-23.23-23.23h-440z"/>
|
||||||
|
<path fill="#333" d="M23.23 357.82C10.4 357.82.002 368.22 0 381.05v511.427c.002 12.83 10.4 23.23 23.23 23.23h38.2v24.118c2.08 25.815 20.27 23.748 33.1 23.75 0 0-11.976-16.96-12.05-40.988-.057-17.923-9.03-12.008-8.176-39.76 2.743-237.84-2.423-390.158.37-522.93z"/>
|
||||||
|
<path fill="#fd5" d="M23.508 286.934A23.51 18.415 0 0 0 0 305.347v69.375a23.51 18.415 0 0 0 23.508 18.413h440a23.51 18.415 0 0 0 23.508-18.413v-69.375a23.51 18.415 0 0 0-23.508-18.413h-440z"/>
|
||||||
|
<path fill="#c87137" d="M77.156 216.362c-5.698 0-10.283 4.588-10.283 10.286v94.03c0 5.7 4.585 10.286 10.283 10.286h24.98c5.697 0 10.284-4.587 10.284-10.285v-94.034c0-5.698-4.587-10.286-10.285-10.286h-24.98zm10.18 10.37h4.018c5.095 0 9.197 4.103 9.197 9.2v28.032c0 5.096-4.1 9.197-9.194 9.197h-4.018c-5.096 0-9.2-4.1-9.2-9.194V235.93c0-5.095 4.104-9.197 9.2-9.197zm288.814-10.37c-5.697 0-10.283 4.588-10.283 10.286v94.03c0 5.7 4.586 10.286 10.283 10.286h24.98c5.697 0 10.284-4.587 10.284-10.285v-94.034c0-5.698-4.587-10.286-10.285-10.286h-24.98zm11.045 11.885h4.02c5.095 0 9.197 4.102 9.197 9.197v28.032c0 5.095-4.102 9.2-9.197 9.2h-4.02c-5.095 0-9.197-4.105-9.197-9.2v-28.032c0-5.095 4.102-9.197 9.197-9.197z"/>
|
||||||
|
<path fill="#fc0" d="M170.587 306.637a17.633 17.633 0 0 0-17.63 17.63v67.587a17.633 17.633 0 0 0 17.63 17.63h34.852v20.57c0 15.162 12.756 27.915 27.913 27.915h24.976c15.157 0 27.916-12.756 27.916-27.917v-20.57h38.612a17.633 17.633 0 0 0 17.63-17.63v-67.587a17.633 17.633 0 0 0-17.63-17.63H170.585z"/>
|
||||||
|
<rect width="126.356" height="29.385" x="272.569" y="914.707" fill="#b3b3b3" ry="14.693"/>
|
||||||
|
<rect width="169.991" height="457.913" x="300.928" y="430.348" fill="#b3b3b3" ry="27.415"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
@ -2,6 +2,7 @@
|
|||||||
* Control currents in Pins for analog/digital signals, servos, i2c, ...
|
* Control currents in Pins for analog/digital signals, servos, i2c, ...
|
||||||
*/
|
*/
|
||||||
//% color=#A80000 weight=30
|
//% color=#A80000 weight=30
|
||||||
|
//% advanced=true
|
||||||
namespace pins {
|
namespace pins {
|
||||||
/**
|
/**
|
||||||
* Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.
|
* Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
"game.ts",
|
"game.ts",
|
||||||
"led.cpp",
|
"led.cpp",
|
||||||
"led.ts",
|
"led.ts",
|
||||||
|
"motors.cpp",
|
||||||
"music.ts",
|
"music.ts",
|
||||||
"pins.cpp",
|
"pins.cpp",
|
||||||
"pins.ts",
|
"pins.ts",
|
||||||
@ -31,6 +32,7 @@
|
|||||||
"pxtparts.json",
|
"pxtparts.json",
|
||||||
"parts/speaker.svg",
|
"parts/speaker.svg",
|
||||||
"parts/headphone.svg",
|
"parts/headphone.svg",
|
||||||
|
"parts/dcmotor.svg",
|
||||||
"_locales/fr/microbit-jsdoc-strings.json"
|
"_locales/fr/microbit-jsdoc-strings.json"
|
||||||
],
|
],
|
||||||
"public": true,
|
"public": true,
|
||||||
@ -41,8 +43,7 @@
|
|||||||
"microbit-dal": {
|
"microbit-dal": {
|
||||||
"bluetooth": {
|
"bluetooth": {
|
||||||
"enabled": 0
|
"enabled": 0
|
||||||
},
|
}
|
||||||
"debug": 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,5 +144,26 @@
|
|||||||
{"part": true, "pinIndices": [0]},
|
{"part": true, "pinIndices": [0]},
|
||||||
{"pinIndices": [1]}
|
{"pinIndices": [1]}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"dcmotor": {
|
||||||
|
"numberOfPins": 2,
|
||||||
|
"visual": {
|
||||||
|
"image": "parts/dcmotor.svg",
|
||||||
|
"width": 488,
|
||||||
|
"height": 836,
|
||||||
|
"pinDistance": 65,
|
||||||
|
"pinLocations": [
|
||||||
|
{"x": 89, "y": 48},
|
||||||
|
{"x": 395, "y": 48} ]
|
||||||
|
},
|
||||||
|
"pinDefinitions": [
|
||||||
|
{ "target": "P1", "style": "croc", "orientation": "-Z"},
|
||||||
|
{ "target": "ground", "style": "croc", "orientation": "-Z"}
|
||||||
|
],
|
||||||
|
"instantiation": {"kind": "singleton"},
|
||||||
|
"assembly": [
|
||||||
|
{"part": true, "pinIndices": [0]},
|
||||||
|
{"pinIndices": [1]}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ enum class BaudRate {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//% weight=2 color=30
|
//% weight=2 color=30
|
||||||
|
//% advanced=true
|
||||||
namespace serial {
|
namespace serial {
|
||||||
// note that at least one // followed by % is needed per declaration!
|
// note that at least one // followed by % is needed per declaration!
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* Reading and writing data over a serial connection.
|
* Reading and writing data over a serial connection.
|
||||||
*/
|
*/
|
||||||
//% weight=2 color=#002050
|
//% weight=2 color=#002050
|
||||||
|
//% advanced=true
|
||||||
namespace serial {
|
namespace serial {
|
||||||
/**
|
/**
|
||||||
* Prints a line of text to the serial
|
* Prints a line of text to the serial
|
||||||
|
87
libs/core/shims.d.ts
vendored
87
libs/core/shims.d.ts
vendored
@ -5,6 +5,7 @@
|
|||||||
* Creation, manipulation and display of LED images.
|
* Creation, manipulation and display of LED images.
|
||||||
*/
|
*/
|
||||||
//% color=#5C2D91 weight=31
|
//% color=#5C2D91 weight=31
|
||||||
|
//% advanced=true
|
||||||
declare namespace images {
|
declare namespace images {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,6 +129,13 @@ declare interface Image {
|
|||||||
//% color=#0078D7 weight=100
|
//% color=#0078D7 weight=100
|
||||||
declare namespace basic {
|
declare namespace basic {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color on the build-in LED. Set to 0 to turn off.
|
||||||
|
*/
|
||||||
|
//% blockId=device_set_led_color block="set led to %color=color_id" icon="\uf00a"
|
||||||
|
//% weight=50 shim=basic::setLedColor
|
||||||
|
function setLedColor(color: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.
|
* Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.
|
||||||
* @param interval speed of scroll; eg: 150, 100, 200, -100
|
* @param interval speed of scroll; eg: 150, 100, 200, -100
|
||||||
@ -247,13 +255,14 @@ declare namespace input {
|
|||||||
* @param body the code to run when the pin is released
|
* @param body the code to run when the pin is released
|
||||||
*/
|
*/
|
||||||
//% help=input/on-pin-released weight=6 blockGap=8
|
//% help=input/on-pin-released weight=6 blockGap=8
|
||||||
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" shim=input::onPinReleased
|
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
|
||||||
|
//% advanced=true shim=input::onPinReleased
|
||||||
function onPinReleased(name: TouchPin, body: () => void): void;
|
function onPinReleased(name: TouchPin, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the button state (pressed or not) for ``A`` and ``B``.
|
* Get the button state (pressed or not) for ``A`` and ``B``.
|
||||||
*/
|
*/
|
||||||
//% help=input/button-is-pressed weight=57
|
//% help=input/button-is-pressed weight=60
|
||||||
//% block="button|%NAME|is pressed"
|
//% block="button|%NAME|is pressed"
|
||||||
//% blockId=device_get_button2
|
//% blockId=device_get_button2
|
||||||
//% icon="\uf192" blockGap=8
|
//% icon="\uf192" blockGap=8
|
||||||
@ -264,11 +273,28 @@ declare namespace input {
|
|||||||
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
|
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
|
||||||
* @param name pin used to detect the touch
|
* @param name pin used to detect the touch
|
||||||
*/
|
*/
|
||||||
//% help=input/pin-is-pressed weight=56
|
//% help=input/pin-is-pressed weight=58
|
||||||
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
|
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
|
||||||
//% blockGap=8 shim=input::pinIsPressed
|
//% blockGap=8 shim=input::pinIsPressed
|
||||||
function pinIsPressed(name: TouchPin): boolean;
|
function pinIsPressed(name: TouchPin): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
|
||||||
|
* @param dimension TODO
|
||||||
|
*/
|
||||||
|
//% help=input/acceleration weight=58 icon="\uf135"
|
||||||
|
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
||||||
|
//% parts="accelerometer" shim=input::acceleration
|
||||||
|
function acceleration(dimension: Dimension): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
||||||
|
*/
|
||||||
|
//% help=input/light-level weight=57
|
||||||
|
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
||||||
|
//% parts="ledmatrix" shim=input::lightLevel
|
||||||
|
function lightLevel(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current compass heading in degrees.
|
* Get the current compass heading in degrees.
|
||||||
*/
|
*/
|
||||||
@ -287,30 +313,13 @@ declare namespace input {
|
|||||||
//% parts="thermometer" shim=input::temperature
|
//% parts="thermometer" shim=input::temperature
|
||||||
function temperature(): number;
|
function temperature(): number;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
|
|
||||||
* @param dimension TODO
|
|
||||||
*/
|
|
||||||
//% help=input/acceleration weight=54 icon="\uf135"
|
|
||||||
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
|
|
||||||
//% parts="accelerometer" shim=input::acceleration
|
|
||||||
function acceleration(dimension: Dimension): number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
|
|
||||||
*/
|
|
||||||
//% help=input/light-level weight=53
|
|
||||||
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
|
|
||||||
//% parts="ledmatrix" shim=input::lightLevel
|
|
||||||
function lightLevel(): number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.
|
* The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.
|
||||||
* @param kind TODO
|
* @param kind TODO
|
||||||
*/
|
*/
|
||||||
//% help=input/rotation weight=52
|
//% help=input/rotation weight=52
|
||||||
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
|
||||||
//% parts="accelerometer" shim=input::rotation
|
//% parts="accelerometer" advanced=true shim=input::rotation
|
||||||
function rotation(kind: Rotation): number;
|
function rotation(kind: Rotation): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -319,14 +328,16 @@ declare namespace input {
|
|||||||
*/
|
*/
|
||||||
//% help=input/magnetic-force weight=51
|
//% help=input/magnetic-force weight=51
|
||||||
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
|
||||||
//% parts="compass" shim=input::magneticForce
|
//% parts="compass"
|
||||||
|
//% advanced=true shim=input::magneticForce
|
||||||
function magneticForce(dimension: Dimension): number;
|
function magneticForce(dimension: Dimension): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of milliseconds elapsed since power on.
|
* Gets the number of milliseconds elapsed since power on.
|
||||||
*/
|
*/
|
||||||
//% help=input/running-time weight=50
|
//% help=input/running-time weight=50
|
||||||
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017" shim=input::runningTime
|
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
|
||||||
|
//% advanced=true shim=input::runningTime
|
||||||
function runningTime(): number;
|
function runningTime(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,13 +353,15 @@ declare namespace input {
|
|||||||
//% help=input/set-accelerometer-range
|
//% help=input/set-accelerometer-range
|
||||||
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
|
||||||
//% weight=5
|
//% weight=5
|
||||||
//% parts="accelerometer" shim=input::setAccelerometerRange
|
//% parts="accelerometer"
|
||||||
|
//% advanced=true shim=input::setAccelerometerRange
|
||||||
function setAccelerometerRange(range: AcceleratorRange): void;
|
function setAccelerometerRange(range: AcceleratorRange): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//% weight=1 color="#333333"
|
//% weight=1 color="#333333"
|
||||||
|
//% advanced=true
|
||||||
declare namespace control {
|
declare namespace control {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -457,7 +470,8 @@ declare namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/brightness weight=60
|
//% help=led/brightness weight=60
|
||||||
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
|
||||||
//% parts="ledmatrix" shim=led::brightness
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true shim=led::brightness
|
||||||
function brightness(): number;
|
function brightness(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -466,7 +480,8 @@ declare namespace led {
|
|||||||
*/
|
*/
|
||||||
//% help=led/set-brightness weight=59
|
//% help=led/set-brightness weight=59
|
||||||
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
|
||||||
//% parts="ledmatrix" shim=led::setBrightness
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true shim=led::setBrightness
|
||||||
function setBrightness(value: number): void;
|
function setBrightness(value: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,7 +489,8 @@ declare namespace led {
|
|||||||
*/
|
*/
|
||||||
//% weight=50 help=led/stop-animation
|
//% weight=50 help=led/stop-animation
|
||||||
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
|
||||||
//% parts="ledmatrix" shim=led::stopAnimation
|
//% parts="ledmatrix"
|
||||||
|
//% advanced=true shim=led::stopAnimation
|
||||||
function stopAnimation(): void;
|
function stopAnimation(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -492,6 +508,22 @@ declare namespace led {
|
|||||||
//% parts="ledmatrix" shim=led::screenshot
|
//% parts="ledmatrix" shim=led::screenshot
|
||||||
function screenshot(): Image;
|
function screenshot(): Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks to control the onboard motors
|
||||||
|
*/
|
||||||
|
//% weight=30
|
||||||
|
declare namespace motors {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls the power sent to a single motor
|
||||||
|
* @param power %percent of power sent to the motor. Negative power goes backward. eg: 50
|
||||||
|
*/
|
||||||
|
//% blockId=motor_on block="motor on at %percent|%"
|
||||||
|
//% parts=dcmotor shim=motors::motorOn
|
||||||
|
function motorOn(power: number): void;
|
||||||
|
}
|
||||||
declare namespace pins {
|
declare namespace pins {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -636,6 +668,7 @@ declare namespace pins {
|
|||||||
|
|
||||||
|
|
||||||
//% weight=2 color=30
|
//% weight=2 color=30
|
||||||
|
//% advanced=true
|
||||||
declare namespace serial {
|
declare namespace serial {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
basic.setLedColor(Colors.Blue)
|
||||||
|
basic.pause(500)
|
||||||
|
basic.setLedColor(Colors.Red)
|
||||||
|
basic.pause(500)
|
||||||
|
basic.setLedColor(Colors.Green)
|
||||||
|
basic.pause(500)
|
||||||
|
basic.setLedColor(0);
|
||||||
|
basic.setLedColor(Colors.Violet)
|
||||||
|
basic.pause(100)
|
||||||
led.plot(0, 0)
|
led.plot(0, 0)
|
||||||
basic.pause(1000);
|
basic.pause(1000);
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
],
|
],
|
||||||
"public": true,
|
"public": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core": "file:../core",
|
"core": "file:../core"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ namespace radio {
|
|||||||
//% help=radio/write-value-to-serial
|
//% help=radio/write-value-to-serial
|
||||||
//% weight=3
|
//% weight=3
|
||||||
//% blockId=radio_write_value_serial block="radio write value to serial"
|
//% blockId=radio_write_value_serial block="radio write value to serial"
|
||||||
|
//% advanced=true
|
||||||
void writeValueToSerial() {
|
void writeValueToSerial() {
|
||||||
if (radioEnable() != MICROBIT_OK) return;
|
if (radioEnable() != MICROBIT_OK) return;
|
||||||
PacketBuffer p = uBit.radio.datagram.recv();
|
PacketBuffer p = uBit.radio.datagram.recv();
|
||||||
@ -198,6 +199,7 @@ namespace radio {
|
|||||||
//% help=radio/received-signal-strength
|
//% help=radio/received-signal-strength
|
||||||
//% weight=40
|
//% weight=40
|
||||||
//% blockId=radio_datagram_rssi block="radio received signal strength"
|
//% blockId=radio_datagram_rssi block="radio received signal strength"
|
||||||
|
//% advanced=true
|
||||||
int receivedSignalStrength() {
|
int receivedSignalStrength() {
|
||||||
if (radioEnable() != MICROBIT_OK) return 0;
|
if (radioEnable() != MICROBIT_OK) return 0;
|
||||||
return packet.getRSSI();
|
return packet.getRSSI();
|
||||||
@ -208,7 +210,7 @@ namespace radio {
|
|||||||
* @ param id the group id between ``0`` and ``255``, 1 eg
|
* @ param id the group id between ``0`` and ``255``, 1 eg
|
||||||
*/
|
*/
|
||||||
//% help=radio/set-group
|
//% help=radio/set-group
|
||||||
//% weight=10 blockGap=8
|
//% weight=10 blockGap=8 advanced=true
|
||||||
//% blockId=radio_set_group block="radio set group %ID"
|
//% blockId=radio_set_group block="radio set group %ID"
|
||||||
void setGroup(int id) {
|
void setGroup(int id) {
|
||||||
if (radioEnable() != MICROBIT_OK) return;
|
if (radioEnable() != MICROBIT_OK) return;
|
||||||
@ -222,6 +224,7 @@ namespace radio {
|
|||||||
//% help=radio/set-transmit-power
|
//% help=radio/set-transmit-power
|
||||||
//% weight=9 blockGap=8
|
//% weight=9 blockGap=8
|
||||||
//% blockId=radio_set_transmit_power block="radio set transmit power %power"
|
//% blockId=radio_set_transmit_power block="radio set transmit power %power"
|
||||||
|
//% advanced=true
|
||||||
void setTransmitPower(int power) {
|
void setTransmitPower(int power) {
|
||||||
if (radioEnable() != MICROBIT_OK) return;
|
if (radioEnable() != MICROBIT_OK) return;
|
||||||
uBit.radio.setTransmitPower(power);
|
uBit.radio.setTransmitPower(power);
|
||||||
@ -229,10 +232,12 @@ namespace radio {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the radio to transmit the serial number in each message.
|
* Set the radio to transmit the serial number in each message.
|
||||||
|
* @param transmit value indicating if the serial number is transmitted, eg: true
|
||||||
*/
|
*/
|
||||||
//% help=radio/set-transmit-serial-number
|
//% help=radio/set-transmit-serial-number
|
||||||
//% weight=8 blockGap=8
|
//% weight=8 blockGap=8
|
||||||
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit"
|
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit"
|
||||||
|
//% advanced=true
|
||||||
void setTransmitSerialNumber(bool transmit) {
|
void setTransmitSerialNumber(bool transmit) {
|
||||||
if (radioEnable() != MICROBIT_OK) return;
|
if (radioEnable() != MICROBIT_OK) return;
|
||||||
transmitSerialNumber = transmit;
|
transmitSerialNumber = transmit;
|
||||||
|
15
libs/radio/shims.d.ts
vendored
15
libs/radio/shims.d.ts
vendored
@ -38,7 +38,8 @@ declare namespace radio {
|
|||||||
*/
|
*/
|
||||||
//% help=radio/write-value-to-serial
|
//% help=radio/write-value-to-serial
|
||||||
//% weight=3
|
//% weight=3
|
||||||
//% blockId=radio_write_value_serial block="radio write value to serial" shim=radio::writeValueToSerial
|
//% blockId=radio_write_value_serial block="radio write value to serial"
|
||||||
|
//% advanced=true shim=radio::writeValueToSerial
|
||||||
function writeValueToSerial(): void;
|
function writeValueToSerial(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +80,8 @@ declare namespace radio {
|
|||||||
*/
|
*/
|
||||||
//% help=radio/received-signal-strength
|
//% help=radio/received-signal-strength
|
||||||
//% weight=40
|
//% weight=40
|
||||||
//% blockId=radio_datagram_rssi block="radio received signal strength" shim=radio::receivedSignalStrength
|
//% blockId=radio_datagram_rssi block="radio received signal strength"
|
||||||
|
//% advanced=true shim=radio::receivedSignalStrength
|
||||||
function receivedSignalStrength(): number;
|
function receivedSignalStrength(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +89,7 @@ declare namespace radio {
|
|||||||
* @ param id the group id between ``0`` and ``255``, 1 eg
|
* @ param id the group id between ``0`` and ``255``, 1 eg
|
||||||
*/
|
*/
|
||||||
//% help=radio/set-group
|
//% help=radio/set-group
|
||||||
//% weight=10 blockGap=8
|
//% weight=10 blockGap=8 advanced=true
|
||||||
//% blockId=radio_set_group block="radio set group %ID" shim=radio::setGroup
|
//% blockId=radio_set_group block="radio set group %ID" shim=radio::setGroup
|
||||||
function setGroup(id: number): void;
|
function setGroup(id: number): void;
|
||||||
|
|
||||||
@ -97,15 +99,18 @@ declare namespace radio {
|
|||||||
*/
|
*/
|
||||||
//% help=radio/set-transmit-power
|
//% help=radio/set-transmit-power
|
||||||
//% weight=9 blockGap=8
|
//% weight=9 blockGap=8
|
||||||
//% blockId=radio_set_transmit_power block="radio set transmit power %power" shim=radio::setTransmitPower
|
//% blockId=radio_set_transmit_power block="radio set transmit power %power"
|
||||||
|
//% advanced=true shim=radio::setTransmitPower
|
||||||
function setTransmitPower(power: number): void;
|
function setTransmitPower(power: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the radio to transmit the serial number in each message.
|
* Set the radio to transmit the serial number in each message.
|
||||||
|
* @param transmit value indicating if the serial number is transmitted, eg: true
|
||||||
*/
|
*/
|
||||||
//% help=radio/set-transmit-serial-number
|
//% help=radio/set-transmit-serial-number
|
||||||
//% weight=8 blockGap=8
|
//% weight=8 blockGap=8
|
||||||
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit" shim=radio::setTransmitSerialNumber
|
//% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit"
|
||||||
|
//% advanced=true shim=radio::setTransmitSerialNumber
|
||||||
function setTransmitSerialNumber(transmit: boolean): void;
|
function setTransmitSerialNumber(transmit: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-calliope",
|
"name": "pxt-calliope",
|
||||||
"version": "0.5.2",
|
"version": "0.5.7",
|
||||||
"description": "calliope target for PXT",
|
"description": "calliope target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.4.51"
|
"pxt-core": "0.4.54"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@
|
|||||||
"yottaTarget": "bbc-microbit-classic-gcc",
|
"yottaTarget": "bbc-microbit-classic-gcc",
|
||||||
"yottaCorePackage": "pxt-calliope-core",
|
"yottaCorePackage": "pxt-calliope-core",
|
||||||
"githubCorePackage": "microsoft/pxt-calliope-core",
|
"githubCorePackage": "microsoft/pxt-calliope-core",
|
||||||
"gittag": "v0.5.5",
|
"gittag": "v0.5.7",
|
||||||
"serviceId": "calliope"
|
"serviceId": "calliope"
|
||||||
},
|
},
|
||||||
"serial": {
|
"serial": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
namespace pxsim.basic {
|
namespace pxsim.basic {
|
||||||
export function setLedColor(c: number) {
|
export function setLedColor(c: number) {
|
||||||
board().rgbLedState = c;
|
board().rgbLedState = c;
|
||||||
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
5
sim/state/soundmotor.ts
Normal file
5
sim/state/soundmotor.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace pxsim.motors {
|
||||||
|
export function motorOn(power: number) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
@ -352,8 +352,16 @@ namespace pxsim.visuals {
|
|||||||
let state = this.board;
|
let state = this.board;
|
||||||
if (state.rgbLedState) {
|
if (state.rgbLedState) {
|
||||||
if (!this.rgbLed)
|
if (!this.rgbLed)
|
||||||
this.rgbLed = svg.child(this.g, "circle", { cx: 170, cy: 200 });
|
this.rgbLed = svg.child(this.g, "circle", { cx: 170, cy: 190, r:5 });
|
||||||
svg.fill(this.rgbLed, svg.toHtmlColor(state.rgbLedState));
|
const c = state.rgbLedState;
|
||||||
|
const b = c & 0xFF;
|
||||||
|
const g = (c >> 8) & 0xFF;
|
||||||
|
const r = (c >> 16) & 0xFF;
|
||||||
|
const w = (c >> 24) & 0xFF;
|
||||||
|
const ch = `rgba(${r}, ${g}, ${b}, 1)`;
|
||||||
|
svg.fill(this.rgbLed, ch);
|
||||||
|
} else if (this.rgbLed) {
|
||||||
|
svg.fill(this.rgbLed, 'white');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user