Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
37330188ef | |||
4922a4a833 | |||
9db5db5067 | |||
75331e4297 | |||
cdc0d12a98 | |||
e08148cac6 | |||
e947f4859b | |||
92508d2daf | |||
5098eaac5a | |||
3a0d4df65c | |||
c26a81dee9 | |||
0054dede9a | |||
7e9c646684 | |||
b2282b1a81 | |||
e4c0e582d3 | |||
0e18b13ea1 | |||
ab6268ea7a | |||
999a40bb0d | |||
0d4af4ea12 | |||
5209222438 | |||
f21ff4ad20 | |||
2d5a96d215 | |||
30fe647f51 | |||
2361d1910a | |||
7921caaaff | |||
8bf34ae19c | |||
0dc03c81b7 | |||
1a398e0db9 | |||
f614cb9b2b | |||
794909f09f | |||
24107d1968 | |||
dfca86999f | |||
a487c3d3ac | |||
e7ea0ba581 | |||
212da01f5b | |||
4e72713797 | |||
5d27ddb4a5 |
@ -7,14 +7,17 @@ Here are some fun programs for your @boardname@!
|
||||
```codecard
|
||||
[{
|
||||
"name": "Blinky",
|
||||
"description": "A blinking LED",
|
||||
"url":"/examples/blinky"
|
||||
},
|
||||
{
|
||||
"name": "Name Tag",
|
||||
"description": "Scroll your name on the screen",
|
||||
"url":"/examples/name-tag"
|
||||
},
|
||||
{
|
||||
"name": "Rando",
|
||||
"description": "Randomly blinking LEDs",
|
||||
"url":"/examples/rando"
|
||||
}]
|
||||
```
|
||||
@ -24,12 +27,15 @@ Here are some fun programs for your @boardname@!
|
||||
```codecard
|
||||
[{
|
||||
"name": "Plot Acceleration",
|
||||
"description": "chart acceleration on the LED screen",
|
||||
"url":"/examples/plot-acceleration"
|
||||
}, {
|
||||
"name": "Plot Light Level",
|
||||
"description": "chart light level on the LED screen",
|
||||
"url":"/examples/plot-light-level"
|
||||
}, {
|
||||
"name": "Plot Analog Pin",
|
||||
"description": "chart analog input on the LED screen",
|
||||
"url":"/examples/plot-analog-pin"
|
||||
}]
|
||||
```
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v0.9.11"
|
||||
"appref": "v0.9.23"
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ but this may feel a bit awkward to programmers more comfortable with an object-o
|
||||
and objects are built from these classes.
|
||||
|
||||
Starting with ECMAScript 2015, also known as ECMAScript 6, JavaScript programmers will be able to build their applications using
|
||||
this object-oriented class-based approach. TypeScript, allows you to use these techniques now, compiling them
|
||||
down to JavaScript that works across all major browsers and platforms, without having to wait for the next version of JavaScript.
|
||||
this object-oriented class-based approach. TypeScript, allows you to use these techniques.
|
||||
|
||||
Let's take a look at a simple class-based example:
|
||||
|
||||
@ -34,10 +33,6 @@ This calls into the constructor we defined earlier, creating a new object with t
|
||||
|
||||
# Inheritance
|
||||
|
||||
### ~hint
|
||||
### Inheritance is not supported yet for the @boardname@. Coming soon...
|
||||
### ~
|
||||
|
||||
In TypeScript, we can use common object-oriented patterns.
|
||||
Of course, one of the most fundamental patterns in class-based programming is being able to extend existing classes to create new ones using inheritance.
|
||||
|
||||
|
@ -6,15 +6,14 @@ For the @boardname@, we support a "static" subset of TypeScript (itself a supers
|
||||
|
||||
## Supported language features
|
||||
|
||||
* variables with `let`, `const`, and `var`
|
||||
* variables with `let` and `const`
|
||||
* functions with lexical scoping and recursion
|
||||
* top-level code in the file; hello world really is `console.log("Hello world")`
|
||||
* `if ... else if ... else` statements
|
||||
* `while` and `do ... while` loops
|
||||
* `for(;;)` loops (see below about `for ... in/of`)
|
||||
* `for(;;)` loops and for ... of
|
||||
* `break/continue`; also with labeled loops
|
||||
* `switch` statement (on numbers only)
|
||||
* `debugger` statement for breakpoints
|
||||
* conditional operator `? :`; lazy boolean operators
|
||||
* namespaces (a form of modules)
|
||||
* all arithmetic operators (including bitwise operators); note that in microcontroller targets
|
||||
@ -25,6 +24,7 @@ For the @boardname@, we support a "static" subset of TypeScript (itself a supers
|
||||
* classes with fields, methods and constructors; `new` keyword
|
||||
* array literals `[1, 2, 3]`
|
||||
* enums
|
||||
* class inheritance
|
||||
|
||||
## Unsupported language features
|
||||
|
||||
@ -32,10 +32,10 @@ We generally stay away from the more dynamic parts of JavaScript.
|
||||
Things you may miss and we may implement:
|
||||
|
||||
* exceptions (`throw`, `try ... catch`, `try ... finally`)
|
||||
* `for ... of` statements
|
||||
* `for ... in` statements
|
||||
* object literals `{ foo: 1, bar: "two" }`
|
||||
* method-like properties (get/set accessors)
|
||||
* class inheritance
|
||||
* `debugger` statement for breakpoints
|
||||
|
||||
For JS-only targets we may implement the following:
|
||||
|
||||
@ -55,4 +55,4 @@ Things that we are not very likely to implement:
|
||||
* `eval`
|
||||
* `delete` statement
|
||||
* `for ... in` statements
|
||||
* JSX (HTML as part of JavaScript)
|
||||
* JSX (HTML as part of JavaScript)
|
||||
|
@ -29,8 +29,6 @@ function addToZ(x: number, y: number) {
|
||||
basic.showNumber(addToZ(1, 2))
|
||||
```
|
||||
|
||||
## Typing the function
|
||||
|
||||
Let's add a return type to our add function:
|
||||
|
||||
```typescript
|
||||
@ -41,6 +39,19 @@ function add(x: number, y: number): number {
|
||||
|
||||
TypeScript can figure the return type out by looking at the return statements, so you can optionally leave this off in many cases.
|
||||
|
||||
# Arrow Functions
|
||||
|
||||
Arrow functions (also known as "lamba" functions) are used extensively to provide event handlers for
|
||||
many APIs. For example:
|
||||
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
[Read more about arrow functions...](http://devdocs.io/javascript/functions/arrow_functions)
|
||||
|
||||
# Optional and Default Parameters
|
||||
|
||||
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
|
||||
|
@ -18,13 +18,6 @@ This also is true when simulating in the browser.
|
||||
* comparison operators - [read more](http://devdocs.io/javascript/operators/comparison_operators)
|
||||
* conditional operator - [read more](http://devdocs.io/javascript/operators/conditional_operator)
|
||||
|
||||
## More
|
||||
|
||||
* lambda functions `() => { ... }`
|
||||
* array literals `[1, 2, 3]`
|
||||
* strings, with a few common methods
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
|
||||
### ~button /js/statements
|
||||
NEXT: Statements
|
||||
### ~
|
@ -5,7 +5,6 @@ The following JavaScript statements are supported for the @boardname@:
|
||||
## Variable declarations
|
||||
* `const` statement - [read more](http://devdocs.io/javascript/statements/const)
|
||||
* `let` statement - [read more](http://devdocs.io/javascript/statements/let)
|
||||
* `var` statement - [read more](http://devdocs.io/javascript/statements/var)
|
||||
|
||||
## Block-structured statements
|
||||
|
||||
|
@ -3,6 +3,22 @@
|
||||
For programs to be useful, we need to be able to work with some of the simplest units of data:
|
||||
numbers, strings, structures, boolean values, and the like.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```typescript
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
All the examples below give an example type annotation, but will work just the same without the annotation.
|
||||
|
||||
# Boolean
|
||||
|
||||
The most basic datatype is the simple true/false value, which is called a `boolean` value.
|
||||
@ -77,7 +93,6 @@ let list: Array<number> = [1, 2, 3];
|
||||
For the @boardname@, all elements of an array must have the same type.
|
||||
### ~
|
||||
|
||||
|
||||
# Enum
|
||||
|
||||
A helpful addition to the standard set of datatypes from JavaScript is the `enum`.
|
||||
@ -108,7 +123,6 @@ let c: Color = Color.Green;
|
||||
|
||||
The TypeScript type `any` is not supported in the @boardname@.
|
||||
|
||||
|
||||
# Void
|
||||
|
||||
`void` is the absence of having any type at all.
|
||||
@ -122,21 +136,6 @@ function warnUser(): void {
|
||||
|
||||
Declaring variables of type `void` is not useful.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```typescript
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
|
||||
### ~button /js/classes
|
||||
NEXT: Classes
|
||||
### ~
|
@ -1,6 +1,6 @@
|
||||
# Variable Declarations
|
||||
|
||||
Declaring a variable should be done using the ``let`` keyworld:
|
||||
Declaring a variable should be done using the ``let`` keyword:
|
||||
|
||||
```typescript
|
||||
let a = 10;
|
||||
@ -24,6 +24,10 @@ let a = 10;
|
||||
|
||||
The key difference is not in the syntax, but in the semantics, which we'll now dive into.
|
||||
|
||||
### ~hint
|
||||
### Use `let` instead of `var` to introduce a new variable.
|
||||
### ~
|
||||
|
||||
## Block-scoping
|
||||
|
||||
When a variable is declared using `let`, it uses what some call *lexical-scoping* or *block-scoping*.
|
||||
|
@ -4,6 +4,7 @@ Provides access to basic @boardname@ functionality.
|
||||
|
||||
```cards
|
||||
basic.showNumber(0);
|
||||
basic.showIcon(IconNames.Heart);
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
@ -24,6 +25,7 @@ basic.plotLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
`);
|
||||
basic.showArrow(ArrowNames.North);
|
||||
basic.showAnimation(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
@ -35,6 +37,8 @@ basic.showAnimation(`
|
||||
|
||||
### See Also
|
||||
|
||||
[showNumber](/reference/basic/show-number), [showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string),
|
||||
[showNumber](/reference/basic/show-number),
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string),
|
||||
[clearScreen](/reference/basic/clear-screen), [forever](/reference/basic/forever), [pause](/reference/basic/pause),
|
||||
[showAnimation](/reference/basic/show-animation)
|
||||
|
23
docs/reference/basic/show-arrow.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Show Arrow
|
||||
|
||||
Shows the selected arrow on the LED screen
|
||||
|
||||
```sig
|
||||
basic.showArrow(ArrowNames.North)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program shows all eight arrows.
|
||||
|
||||
```blocks
|
||||
for (let index = 0; index <= 7; index++) {
|
||||
basic.showArrow(index)
|
||||
basic.pause(300)
|
||||
}
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds)
|
21
docs/reference/basic/show-icon.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Show Icon
|
||||
|
||||
Shows the selected icon on the LED screen
|
||||
|
||||
```sig
|
||||
basic.showIcon(IconNames.Heart)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program shows a happy face and then a sad face with the ``show icon`` function, with a one second pause in between.
|
||||
|
||||
```blocks
|
||||
basic.showIcon(IconNames.Happy)
|
||||
basic.pause(1000)
|
||||
basic.showIcon(IconNames.Sad)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[showLeds](/reference/basic/show-leds)
|
29
docs/reference/music/play-builtin-melody.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Play Built-in Melody
|
||||
|
||||
Play a built in 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)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``melody`` is the kind of built-in melody you want to play
|
||||
|
||||
## Example
|
||||
|
||||
This example plays the ``Entertainer`` melody.
|
||||
|
||||
```blocks
|
||||
music.playBuiltinMelody(Melodies.Entertainer)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[play tone](/reference/music/play-tone), [rest](/reference/music/rest), [ring tone](/reference/music/ring-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo),
|
||||
[change tempo by](/reference/music/change-tempo-by)
|
||||
|
BIN
docs/static/blocks/iconnames/heart.PNG
vendored
Before Width: | Height: | Size: 5.0 KiB |
@ -166,6 +166,9 @@
|
||||
"led.unplot|param|y": "TODO",
|
||||
"music": "Generation of music tones through pin ``P0``.",
|
||||
"music.beat": "Returns the duration of a beat in milli-seconds",
|
||||
"music.beginMelody": "Starts playing a melody through pin ``P0``.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
|
||||
"music.beginMelody|param|options": "melody options, once / forever, in the foreground / background",
|
||||
"music.builtInMelody": "Gets the melody array of a built-in melody.",
|
||||
"music.changeTempoBy": "Change the tempo by the specified amount",
|
||||
"music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20",
|
||||
"music.noteFrequency": "Gets the frequency of a note.",
|
||||
|
@ -86,7 +86,6 @@
|
||||
"IconNames.LeftTriangle|block": "left triangle",
|
||||
"IconNames.Meh|block": "meh",
|
||||
"IconNames.No|block": "no",
|
||||
"IconNames.Pacman|block": "pac man",
|
||||
"IconNames.Pitchfork|block": "pitchfork",
|
||||
"IconNames.QuarterNote|block": "quarter note",
|
||||
"IconNames.Rabbit|block": "rabbit",
|
||||
@ -115,6 +114,30 @@
|
||||
"LedSpriteProperty.Y|block": "y",
|
||||
"Math.randomBoolean|block": "pick random true or false",
|
||||
"Math|block": "Math",
|
||||
"Melodies.BaDing|block": "ba ding",
|
||||
"Melodies.Baddy|block": "baddy",
|
||||
"Melodies.Birthday|block": "birthday",
|
||||
"Melodies.Blues|block": "blues",
|
||||
"Melodies.Chase|block": "chase",
|
||||
"Melodies.Dadadadum|block": "dadadum",
|
||||
"Melodies.Entertainer|block": "entertainer",
|
||||
"Melodies.Funeral|block": "funereal",
|
||||
"Melodies.Funk|block": "funk",
|
||||
"Melodies.JumpDown|block": "jump down",
|
||||
"Melodies.JumpUp|block": "jump up",
|
||||
"Melodies.Nyan|block": "nyan",
|
||||
"Melodies.Ode|block": "ode",
|
||||
"Melodies.PowerDown|block": "power down",
|
||||
"Melodies.PowerUp|block": "power up",
|
||||
"Melodies.Prelude|block": "prelude",
|
||||
"Melodies.Punchline|block": "punchline",
|
||||
"Melodies.Ringtone|block": "ringtone",
|
||||
"Melodies.Wawawawaa|block": "wawawawaa",
|
||||
"Melodies.Wedding|block": "wedding",
|
||||
"MelodyOptions.ForeverInBackground|block": "forever in background",
|
||||
"MelodyOptions.Forever|block": "forever",
|
||||
"MelodyOptions.OnceInBackground|block": "once in background",
|
||||
"MelodyOptions.Once|block": "once",
|
||||
"Note.CSharp3|block": "C#3",
|
||||
"Note.CSharp4|block": "C#4",
|
||||
"Note.CSharp5|block": "C#5",
|
||||
@ -200,6 +223,8 @@
|
||||
"led.unplot|block": "unplot|x %x|y %y",
|
||||
"led|block": "led",
|
||||
"music.beat|block": "%fraction|beat",
|
||||
"music.beginMelody|block": "start|melody %melody=device_builtin_melody| repeating %options",
|
||||
"music.builtInMelody|block": "%melody",
|
||||
"music.changeTempoBy|block": "change tempo by (bpm)|%value",
|
||||
"music.noteFrequency|block": "%note",
|
||||
"music.playTone|block": "play|tone %note=device_note|for %duration=device_beat",
|
||||
|
@ -1,4 +1,44 @@
|
||||
{
|
||||
"Gesture.LogoDown": "Déclenché lorsque le logo est vers le bas et l’écran est vertical",
|
||||
"Gesture.LogoDown|block": "logo vers le bas",
|
||||
"Gesture.LogoUp|block": "logo vers le haut",
|
||||
"Gesture.ScreenDown|block": "écran vers le bas",
|
||||
"Gesture.ScreenUp|block": "écran vers le haut",
|
||||
"Gesture.Shake|block": "secouer",
|
||||
"Gesture.SixG|block": "6g",
|
||||
"Gesture.TiltLeft|block": "incliner à gauche",
|
||||
"Gesture.TiltRight|block": "incliner à droite",
|
||||
"IconNames.Angry|block": "fâché",
|
||||
"IconNames.Asleep|block": "endormi",
|
||||
"IconNames.Butterfly|block": "papillon",
|
||||
"IconNames.Chessboard|block": "échiquier",
|
||||
"IconNames.Confused|block": "confus",
|
||||
"IconNames.Cow|block": "vache",
|
||||
"IconNames.Diamond|block": "diamant",
|
||||
"IconNames.Duck|block": "canard",
|
||||
"IconNames.Fabulous|block": "fabuleux",
|
||||
"IconNames.Ghost|block": "fantôme",
|
||||
"IconNames.Giraffe|block": "girafe",
|
||||
"IconNames.Happy|block": "heureux",
|
||||
"IconNames.Heart|block": "coeur",
|
||||
"IconNames.House|block": "maison",
|
||||
"IconNames.LeftTriangle|block": "triangle gauche",
|
||||
"IconNames.Meh|block": "meh",
|
||||
"IconNames.No|block": "non",
|
||||
"IconNames.Pacman|block": "pac man",
|
||||
"IconNames.Pitchfork|block": "pitchfork",
|
||||
"IconNames.QuarterNote|block": "note",
|
||||
"IconNames.Rabbit|block": "lapin",
|
||||
"IconNames.Rollerskate|block": "patins à roulette",
|
||||
"IconNames.Sad|block": "triste",
|
||||
"IconNames.Silly|block": "bête",
|
||||
"IconNames.Skull|block": "crâne",
|
||||
"IconNames.SmallDiamond|block": "petit diamant",
|
||||
"IconNames.SmallHeart|block": "petit coeur",
|
||||
"IconNames.SmallSquare|block": "petit carré",
|
||||
"IconNames.Snake|block": "serpent",
|
||||
"IconNames.Square|block": "carré",
|
||||
"LedSpriteProperty.Blink|block": "clignotement",
|
||||
"LedSpriteProperty.Brightness|block": "luminosité",
|
||||
"Math.randomBoolean|block": "choisir au hasard vrai ou faux",
|
||||
"Math|block": "Maths",
|
||||
@ -30,6 +70,7 @@
|
||||
"input.magneticForce|block": "force magnétique (µT) |%NAME",
|
||||
"input.onButtonPressed|block": "lorsque le button|%NAME|est pressé",
|
||||
"input.onGesture|block": "lorsque|%NAME",
|
||||
"input.onPinPressed|block": "lorsque le pin %NAME|est pressé",
|
||||
"input.onPinReleased|block": "lorsque la broche %NAME|est lachée",
|
||||
"input.pinIsPressed|block": "broche %NAME| est pressée",
|
||||
"input.rotation|block": "rotation (°)|%NAME",
|
||||
|
@ -1,7 +1,12 @@
|
||||
{
|
||||
"Math.randomBoolean": "「真」か「偽」をランダムに生成します。",
|
||||
"basic.clearScreen": "すべてのLEDをオフにします。",
|
||||
"basic.forever": "ずっとコードをバックグラウンドで繰り返し実行します。",
|
||||
"basic.pause": "ミリ秒で指定された時間、一時停止します。",
|
||||
"basic.plotLeds": "LED 画面にイメージを描画します。",
|
||||
"basic.showIcon": "選択されたアイコンを、LED画面に表示します。",
|
||||
"basic.showLeds": "LED 画面にイメージを描画します。",
|
||||
"basic.showNumber": "画面上のに数字をスクロールさせます。数が1桁で、画面上に収まる場合、スクロールしません。",
|
||||
"basic.showString": "一度に1文字ずつ、テキストを画面に表示します。1文字だけの場合は、スクロールしません。",
|
||||
"input.acceleration": "加速度値を取得します。(スクリーンを上に向けて置いたとき、xは0、yも0、zは-1024です)",
|
||||
"input.buttonIsPressed": "``A`` か ``B`` のボタンが押されているかを取得します。",
|
||||
@ -10,6 +15,7 @@
|
||||
"input.onButtonPressed": "ボタン (``A``, ``B`` or both ``A+B``) が押されたときに実行されます。",
|
||||
"input.onGesture": "ジェスチャ(例えば、ゆさぶる)が行われたときに実行します。",
|
||||
"input.onPinPressed": "ピンが押されたときに実行されます。",
|
||||
"input.onPinReleased": "ピンがタッチされなくなったときに実行されます。",
|
||||
"input.pinIsPressed": "ピンがタッチされているかの状態を取得します。状態を取得するためには、グラウンドにつながっている必要があります。",
|
||||
"input.rotation": "デバイスの、ピッチかロールを度数で取得します。",
|
||||
"input.runningTime": "電源が入ってから経過したミリ秒数を取得します。",
|
||||
|
@ -107,6 +107,7 @@
|
||||
"basic.clearScreen|block": "表示を消す",
|
||||
"basic.forever|block": "ずっと",
|
||||
"basic.pause|block": "一時停止(ミリ秒) %pause",
|
||||
"basic.showIcon|block": "アイコン %i を表示",
|
||||
"basic.showLeds|block": "LEDに表示",
|
||||
"basic.showNumber|block": "数を表示|%number",
|
||||
"basic.showString|block": "文字列を表示|%text",
|
||||
|
@ -10,7 +10,7 @@ namespace Math {
|
||||
* Generates a `true` or `false` value randomly, just like flipping a coin.
|
||||
*/
|
||||
//% blockId=logic_random block="pick random true or false"
|
||||
//% help=math/random-boolean color=230
|
||||
//% help=math/random-boolean
|
||||
export function randomBoolean(): boolean {
|
||||
return Math.random(2) == 0;
|
||||
}
|
||||
|
@ -27,85 +27,122 @@ THE SOFTWARE.
|
||||
|
||||
enum IconNames {
|
||||
//% block="heart"
|
||||
//% blockImage=1
|
||||
Heart = 0,
|
||||
//% block="small heart"
|
||||
//% blockImage=1
|
||||
SmallHeart,
|
||||
//% block="yes"
|
||||
//% blockImage=1
|
||||
Yes,
|
||||
//% block="no"
|
||||
//% blockImage=1
|
||||
No,
|
||||
//% block="happy"
|
||||
//% blockImage=1
|
||||
Happy,
|
||||
//% block="sad"
|
||||
//% blockImage=1
|
||||
Sad,
|
||||
//% block="confused"
|
||||
//% blockImage=1
|
||||
Confused,
|
||||
//% block="angry"
|
||||
//% blockImage=1
|
||||
Angry,
|
||||
//% block="asleep"
|
||||
//% blockImage=1
|
||||
Asleep,
|
||||
//% block="surprised"
|
||||
//% blockImage=1
|
||||
Surprised,
|
||||
//% block="silly"
|
||||
//% blockImage=1
|
||||
Silly,
|
||||
//% block="fabulous"
|
||||
//% blockImage=1
|
||||
Fabulous,
|
||||
//% block="meh"
|
||||
//% blockImage=1
|
||||
Meh,
|
||||
//% block="t-shirt"
|
||||
//% blockImage=1
|
||||
TShirt,
|
||||
//% block="roller skate"
|
||||
//% blockImage=1
|
||||
Rollerskate,
|
||||
//% block="duck"
|
||||
//% blockImage=1
|
||||
Duck,
|
||||
//% block="house"
|
||||
//% blockImage=1
|
||||
House,
|
||||
//% block="tortoise"
|
||||
//% blockImage=1
|
||||
Tortoise,
|
||||
//% block="butterfly"
|
||||
//% blockImage=1
|
||||
Butterfly,
|
||||
//% block="stick figure"
|
||||
//% blockImage=1
|
||||
StickFigure,
|
||||
//% block="ghost"
|
||||
//% blockImage=1
|
||||
Ghost,
|
||||
//% block="sword"
|
||||
//% blockImage=1
|
||||
Sword,
|
||||
//% block="giraffe"
|
||||
//% blockImage=1
|
||||
Giraffe,
|
||||
//% block="skull"
|
||||
//% blockImage=1
|
||||
Skull,
|
||||
//% block="umbrella"
|
||||
//% blockImage=1
|
||||
Umbrella,
|
||||
//% block="snake"
|
||||
//% blockImage=1
|
||||
Snake,
|
||||
//% block="rabbit"
|
||||
//% blockImage=1
|
||||
Rabbit,
|
||||
//% block="cow"
|
||||
//% blockImage=1
|
||||
Cow,
|
||||
//% block="quarter note"
|
||||
//% blockImage=1
|
||||
QuarterNote,
|
||||
//% block="eigth note"
|
||||
//% blockImage=1
|
||||
EigthNote,
|
||||
//% block="pitchfork"
|
||||
//% blockImage=1
|
||||
Pitchfork,
|
||||
//% block="pac man"
|
||||
Pacman,
|
||||
//% block="target"
|
||||
//% blockImage=1
|
||||
Target,
|
||||
//% block="triangle"
|
||||
//% blockImage=1
|
||||
Triangle,
|
||||
//% block="left triangle"
|
||||
//% blockImage=1
|
||||
LeftTriangle,
|
||||
//% block="chess board"
|
||||
//% blockImage=1
|
||||
Chessboard,
|
||||
//% block="diamond"
|
||||
//% blockImage=1
|
||||
Diamond,
|
||||
//% block="small diamond"
|
||||
//% blockImage=1
|
||||
SmallDiamond,
|
||||
//% block="square"
|
||||
//% blockImage=1
|
||||
Square,
|
||||
//% block="small square"
|
||||
SmallSquare,
|
||||
//% blockImage=1
|
||||
SmallSquare
|
||||
}
|
||||
|
||||
enum ArrowNames {
|
||||
@ -136,6 +173,7 @@ namespace basic {
|
||||
//% blockId=basic_show_icon
|
||||
//% block="show icon %i" icon="\uf00a"
|
||||
//% parts="ledmatrix"
|
||||
//% help=basic/show-icon
|
||||
export function showIcon(icon: IconNames) {
|
||||
let res = images.iconImage(icon)
|
||||
res.showImage(0)
|
||||
@ -146,6 +184,7 @@ namespace basic {
|
||||
//% block="show arrow %i=device_arrow"
|
||||
//% parts="ledmatrix"
|
||||
//% advanced=true
|
||||
//% help=basic/show-arrow
|
||||
export function showArrow(i: number) {
|
||||
let res = images.arrowImage(i)
|
||||
res.showImage(0)
|
||||
@ -453,12 +492,6 @@ namespace images {
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .`;
|
||||
case IconNames.Pacman: return `
|
||||
. # # # #
|
||||
# # # # .
|
||||
# # # . .
|
||||
# # # # .
|
||||
. # # # #`;
|
||||
case IconNames.Target: return `
|
||||
. . # . .
|
||||
. # # # .
|
||||
|
@ -112,7 +112,7 @@ enum class Gesture {
|
||||
EightG = MICROBIT_ACCELEROMETER_EVT_8G
|
||||
};
|
||||
|
||||
//% color=300 weight=99 icon="\uf192"
|
||||
//% color=#B4009E weight=99 icon="\uf192"
|
||||
namespace input {
|
||||
/**
|
||||
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
|
||||
@ -212,7 +212,7 @@ namespace input {
|
||||
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)
|
||||
|
@ -8,7 +8,7 @@ enum class DisplayMode_ {
|
||||
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
|
||||
};
|
||||
|
||||
//% color=3 weight=35 icon="\uf205"
|
||||
//% color=#5C2D91 weight=97 icon="\uf205"
|
||||
namespace led {
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ namespace led {
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on or off the display
|
||||
* Turns on or off the display
|
||||
*/
|
||||
//% help=led/enable blockId=device_led_enable block="led enable %on"
|
||||
//% advanced=true parts="ledmatrix"
|
||||
|
119
libs/core/melodies.ts
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
|
||||
in the accompanying AUTHORS file
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Melodies from file microbitmusictunes.c https://github.com/bbcmicrobit/MicroPython
|
||||
|
||||
enum Melodies {
|
||||
//% block="dadadum" blockIdentity=music.builtInMelody
|
||||
Dadadadum = 0,
|
||||
//% block="entertainer" blockIdentity=music.builtInMelody
|
||||
Entertainer,
|
||||
//% block="prelude" blockIdentity=music.builtInMelody
|
||||
Prelude,
|
||||
//% block="ode" blockIdentity=music.builtInMelody
|
||||
Ode,
|
||||
//% block="nyan" blockIdentity=music.builtInMelody
|
||||
Nyan,
|
||||
//% block="ringtone" blockIdentity=music.builtInMelody
|
||||
Ringtone,
|
||||
//% block="funk" blockIdentity=music.builtInMelody
|
||||
Funk,
|
||||
//% block="blues" blockIdentity=music.builtInMelody
|
||||
Blues,
|
||||
//% block="birthday" blockIdentity=music.builtInMelody
|
||||
Birthday,
|
||||
//% block="wedding" blockIdentity=music.builtInMelody
|
||||
Wedding,
|
||||
//% block="funereal" blockIdentity=music.builtInMelody
|
||||
Funeral,
|
||||
//% block="punchline" blockIdentity=music.builtInMelody
|
||||
Punchline,
|
||||
//% block="baddy" blockIdentity=music.builtInMelody
|
||||
Baddy,
|
||||
//% block="chase" blockIdentity=music.builtInMelody
|
||||
Chase,
|
||||
//% block="ba ding" blockIdentity=music.builtInMelody
|
||||
BaDing,
|
||||
//% block="wawawawaa" blockIdentity=music.builtInMelody
|
||||
Wawawawaa,
|
||||
//% block="jump up" blockIdentity=music.builtInMelody
|
||||
JumpUp,
|
||||
//% block="jump down" blockIdentity=music.builtInMelody
|
||||
JumpDown,
|
||||
//% block="power up" blockIdentity=music.builtInMelody
|
||||
PowerUp,
|
||||
//% block="power down" blockIdentity=music.builtInMelody
|
||||
PowerDown,
|
||||
}
|
||||
|
||||
namespace music {
|
||||
|
||||
export function getMelody(melody: Melodies): string[] {
|
||||
switch (melody) {
|
||||
case Melodies.Dadadadum:
|
||||
return ['r4:2', 'g', 'g', 'g', 'eb:8', 'r:2', 'f', 'f', 'f', 'd:8'];
|
||||
case Melodies.Entertainer:
|
||||
return ['d4:1', 'd#', 'e', 'c5:2', 'e4:1', 'c5:2', 'e4:1', 'c5:3', 'c:1', 'd', 'd#', 'e', 'c', 'd', 'e:2', 'b4:1', 'd5:2', 'c:4'];
|
||||
case Melodies.Prelude:
|
||||
return ['c4:1', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e'];
|
||||
case Melodies.Ode:
|
||||
return ['e4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'e:6', 'd:2', 'd:8', 'e:4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'd:6', 'c:2', 'c:8'];
|
||||
case Melodies.Nyan:
|
||||
return ['f#5:2', 'g#', 'c#:1', 'd#:2', 'b4:1', 'd5:1', 'c#', 'b4:2', 'b', 'c#5', 'd', 'd:1', 'c#', 'b4:1', 'c#5:1', 'd#', 'f#', 'g#', 'd#', 'f#', 'c#', 'd', 'b4', 'c#5', 'b4', 'd#5:2', 'f#', 'g#:1', 'd#', 'f#', 'c#', 'd#', 'b4', 'd5', 'd#', 'd', 'c#', 'b4', 'c#5', 'd:2', 'b4:1', 'c#5', 'd#', 'f#', 'c#', 'd', 'c#', 'b4', 'c#5:2', 'b4', 'c#5', 'b4', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'c#5', 'd#', 'b4', 'e5', 'd#', 'e', 'f#', 'b4:2', 'b', 'f#:1', 'g#', 'b', 'f#', 'e5', 'd#', 'c#', 'b4', 'f#', 'd#', 'e', 'f#', 'b:2', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'b', 'c#5', 'd#', 'b4', 'f#', 'g#', 'f#', 'b:2', 'b:1', 'a#', 'b', 'f#', 'g#', 'b', 'e5', 'd#', 'e', 'f#', 'b4:2', 'c#5'];
|
||||
case Melodies.Ringtone:
|
||||
return ['c4:1', 'd', 'e:2', 'g', 'd:1', 'e', 'f:2', 'a', 'e:1', 'f', 'g:2', 'b', 'c5:4'];
|
||||
case Melodies.Funk:
|
||||
return ['c2:2', 'c', 'd#', 'c:1', 'f:2', 'c:1', 'f:2', 'f#', 'g', 'c', 'c', 'g', 'c:1', 'f#:2', 'c:1', 'f#:2', 'f', 'd#'];
|
||||
case Melodies.Blues:
|
||||
return ['c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'f', 'a', 'c3', 'd', 'd#', 'd', 'c', 'a2', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'g', 'b', 'd3', 'f', 'f2', 'a', 'c3', 'd#', 'c2:2', 'e', 'g', 'e', 'g', 'f', 'e', 'd'];
|
||||
case Melodies.Birthday:
|
||||
return ['c4:3', 'c:1', 'd:4', 'c:4', 'f', 'e:8', 'c:3', 'c:1', 'd:4', 'c:4', 'g', 'f:8', 'c:3', 'c:1', 'c5:4', 'a4', 'f', 'e', 'd', 'a#:3', 'a#:1', 'a:4', 'f', 'g', 'f:8'];
|
||||
case Melodies.Wedding:
|
||||
return ['c4:4', 'f:3', 'f:1', 'f:8', 'c:4', 'g:3', 'e:1', 'f:8', 'c:4', 'f:3', 'a:1', 'c5:4', 'a4:3', 'f:1', 'f:4', 'e:3', 'f:1', 'g:8'];
|
||||
case Melodies.Funeral:
|
||||
return ['c3:4', 'c:3', 'c:1', 'c:4', 'd#:3', 'd:1', 'd:3', 'c:1', 'c:3', 'b2:1', 'c3:4'];
|
||||
case Melodies.Punchline:
|
||||
return ['c4:3', 'g3:1', 'f#', 'g', 'g#:3', 'g', 'r', 'b', 'c4'];
|
||||
case Melodies.Baddy:
|
||||
return ['c3:3', 'r', 'd:2', 'd#', 'r', 'c', 'r', 'f#:8'];
|
||||
case Melodies.Chase:
|
||||
return ['a4:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e', 'b4:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e'];
|
||||
case Melodies.BaDing:
|
||||
return ['b5:1', 'e6:3'];
|
||||
case Melodies.Wawawawaa:
|
||||
return ['e3:3', 'r:1', 'd#:3', 'r:1', 'd:4', 'r:1', 'c#:8'];
|
||||
case Melodies.JumpUp:
|
||||
return ['c5:1', 'd', 'e', 'f', 'g'];
|
||||
case Melodies.JumpDown:
|
||||
return ['g5:1', 'f', 'e', 'd', 'c'];
|
||||
case Melodies.PowerUp:
|
||||
return ['g4:1', 'c5', 'e', 'g:2', 'e:1', 'g:3'];
|
||||
case Melodies.PowerDown:
|
||||
return ['g5:1', 'd#', 'c', 'g4:2', 'b:1', 'c5:3'];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
@ -126,12 +126,24 @@ enum BeatFraction {
|
||||
Breve = 64
|
||||
}
|
||||
|
||||
enum MelodyOptions {
|
||||
//% block="once""
|
||||
Once = 1,
|
||||
//% block="forever"
|
||||
Forever = 2,
|
||||
//% block="once in background"
|
||||
OnceInBackground = 4,
|
||||
//% block="forever in background"
|
||||
ForeverInBackground = 8
|
||||
}
|
||||
|
||||
/**
|
||||
* Generation of music tones through pin ``P0``.
|
||||
*/
|
||||
//% color=#D83B01 weight=98 icon="\uf025"
|
||||
namespace music {
|
||||
let beatsPerMinute: number = 120;
|
||||
let freqTable: number[] = [];
|
||||
|
||||
/**
|
||||
* Plays a tone through pin ``P0`` for the given duration.
|
||||
@ -185,6 +197,7 @@ namespace music {
|
||||
|
||||
function init() {
|
||||
if (beatsPerMinute <= 0) beatsPerMinute = 120;
|
||||
if (freqTable.length == 0) freqTable = [28, 29, 31, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, 4186]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,4 +253,127 @@ namespace music {
|
||||
beatsPerMinute = Math.max(1, bpm);
|
||||
}
|
||||
}
|
||||
|
||||
let currentMelody: Melody;
|
||||
let currentBackgroundMelody: Melody;
|
||||
|
||||
/**
|
||||
* Gets the melody array of a built-in melody.
|
||||
* @param name the note name, eg: Note.C
|
||||
*/
|
||||
//% weight=50 help=music/builtin-melody
|
||||
//% blockId=device_builtin_melody block="%melody"
|
||||
//% blockHidden=true
|
||||
export function builtInMelody(melody: Melodies): string[] {
|
||||
return getMelody(melody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts playing a melody through pin ``P0``.
|
||||
* Notes are expressed as a string of characters with this format: NOTE[octave][:duration]
|
||||
* @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
|
||||
//% blockId=device_start_melody block="start|melody %melody=device_builtin_melody| repeating %options"
|
||||
//% parts="headphone"
|
||||
export function beginMelody(melodyArray: string[], options: MelodyOptions = MelodyOptions.Once) {
|
||||
init();
|
||||
if (currentMelody != undefined) {
|
||||
if (((options & MelodyOptions.OnceInBackground) == 0)
|
||||
&& ((options & MelodyOptions.ForeverInBackground) == 0)
|
||||
&& currentMelody.background == true) {
|
||||
currentBackgroundMelody = currentMelody;
|
||||
}
|
||||
currentMelody = new Melody(melodyArray, options);
|
||||
} else {
|
||||
currentMelody = new Melody(melodyArray, options);
|
||||
// Only start the fiber once
|
||||
control.inBackground(() => {
|
||||
while (currentMelody.hasNextNote()) {
|
||||
playNextNote(currentMelody);
|
||||
if (!currentMelody.hasNextNote() && currentBackgroundMelody) {
|
||||
// Swap the background melody back
|
||||
currentMelody = currentBackgroundMelody;
|
||||
currentBackgroundMelody = null;
|
||||
}
|
||||
}
|
||||
currentMelody = null;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function playNextNote(melody: Melody): void {
|
||||
// cache elements
|
||||
let currNote = melody.nextNote();
|
||||
let currentPos = melody.currentPos;
|
||||
let currentDuration = melody.currentDuration;
|
||||
let currentOctave = melody.currentOctave;
|
||||
|
||||
let note: number;
|
||||
let isrest: boolean = false;
|
||||
let beatPos: number;
|
||||
let parsingOctave: boolean = true;
|
||||
|
||||
for (let pos = 0; pos < currNote.length; pos++) {
|
||||
let noteChar = currNote.charAt(pos);
|
||||
switch (noteChar) {
|
||||
case 'a': case 'A': note = 1; break;
|
||||
case 'b': case 'B': note = 3; break;
|
||||
case 'c': case 'C': note = 4; break;
|
||||
case 'd': case 'D': note = 6; break;
|
||||
case 'e': case 'E': note = 8; break;
|
||||
case 'f': case 'F': note = 9; break;
|
||||
case 'g': case 'G': note = 11; break;
|
||||
case 'r': case 'R': isrest = true; break;
|
||||
case '#': note++; break;
|
||||
case 'b': note--; break;
|
||||
case ':': parsingOctave = false; beatPos = pos; break;
|
||||
default: if (parsingOctave) currentOctave = parseInt(noteChar);
|
||||
}
|
||||
}
|
||||
if (!parsingOctave) {
|
||||
currentDuration = parseInt(currNote.substr(beatPos + 1, currNote.length - beatPos));
|
||||
}
|
||||
let beat = (60000 / beatsPerMinute) / 4;
|
||||
if (isrest) {
|
||||
music.rest(currentDuration * beat)
|
||||
} else {
|
||||
let keyNumber = note + (12 * (currentOctave - 1));
|
||||
let frequency = keyNumber >= 0 && keyNumber < freqTable.length ? freqTable[keyNumber] : 0;
|
||||
music.playTone(frequency, currentDuration * beat);
|
||||
}
|
||||
melody.currentDuration = currentDuration;
|
||||
melody.currentOctave = currentOctave;
|
||||
melody.currentPos = melody.repeating == true && currentPos == melody.melodyArray.length - 1 ? 0 : currentPos + 1;
|
||||
}
|
||||
|
||||
class Melody {
|
||||
public melodyArray: string[];
|
||||
public currentDuration: number;
|
||||
public currentOctave: number;
|
||||
public currentPos: number;
|
||||
public repeating: boolean;
|
||||
public background: boolean;
|
||||
|
||||
constructor(melodyArray: string[], options: MelodyOptions) {
|
||||
this.melodyArray = melodyArray;
|
||||
this.repeating = ((options & MelodyOptions.Forever) != 0);
|
||||
this.repeating = this.repeating ? true : ((options & MelodyOptions.ForeverInBackground) != 0)
|
||||
this.background = ((options & MelodyOptions.OnceInBackground) != 0);
|
||||
this.background = this.background ? true : ((options & MelodyOptions.ForeverInBackground) != 0);
|
||||
this.currentDuration = 4; //Default duration (Crotchet)
|
||||
this.currentOctave = 4; //Middle octave
|
||||
this.currentPos = 0;
|
||||
}
|
||||
|
||||
hasNextNote() {
|
||||
return this.repeating || this.currentPos < this.melodyArray.length;
|
||||
}
|
||||
|
||||
nextNote(): string {
|
||||
const currentNote = this.melodyArray[this.currentPos];
|
||||
return currentNote;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
"led.cpp",
|
||||
"led.ts",
|
||||
"music.ts",
|
||||
"melodies.ts",
|
||||
"pins.cpp",
|
||||
"pins.ts",
|
||||
"serial.cpp",
|
||||
|
@ -34,7 +34,7 @@ enum Delimiters {
|
||||
Hash = 6,
|
||||
};
|
||||
|
||||
//% weight=2 color=30 icon="\uf287"
|
||||
//% weight=2 color=#002050 icon="\uf287"
|
||||
//% advanced=true
|
||||
namespace serial {
|
||||
// note that at least one // followed by % is needed per declaration!
|
||||
|
8
libs/core/shims.d.ts
vendored
@ -212,7 +212,7 @@ declare namespace basic {
|
||||
|
||||
|
||||
|
||||
//% color=300 weight=99 icon="\uf192"
|
||||
//% color=#B4009E weight=99 icon="\uf192"
|
||||
declare namespace input {
|
||||
|
||||
/**
|
||||
@ -430,7 +430,7 @@ declare namespace control {
|
||||
|
||||
|
||||
|
||||
//% color=3 weight=35 icon="\uf205"
|
||||
//% color=#5C2D91 weight=97 icon="\uf205"
|
||||
declare namespace led {
|
||||
|
||||
/**
|
||||
@ -500,7 +500,7 @@ declare namespace led {
|
||||
function setDisplayMode(mode: DisplayMode): void;
|
||||
|
||||
/**
|
||||
* Turns on or off the display
|
||||
* Turns on or off the display
|
||||
*/
|
||||
//% help=led/enable blockId=device_led_enable block="led enable %on"
|
||||
//% advanced=true parts="ledmatrix" shim=led::enable
|
||||
@ -671,7 +671,7 @@ declare namespace pins {
|
||||
|
||||
|
||||
|
||||
//% weight=2 color=30 icon="\uf287"
|
||||
//% weight=2 color=#002050 icon="\uf287"
|
||||
//% advanced=true
|
||||
declare namespace serial {
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
"radio.sendNumber": "無線を使って繋がっているデバイスに、数字をブロードキャストします。",
|
||||
"radio.sendString": "無線で繋がっているデバイスに、文字列とあわせてデバイスのシリアル番号と実行時間をブロードキャストします。",
|
||||
"radio.sendValue": "無線で繋がっているデバイスに、名前と値のペアとあわせてデバイスのシリアル番号と実行時間をブロードキャストします。",
|
||||
"radio.setGroup": "無線のグループ ID を設定します。 1 つのグループ ID上に流れる情報だけを、受信することができます。グループIDは、0-255の間で指定できます。",
|
||||
"radio.setTransmitPower": "無線での送信に使うパワーを指定します。",
|
||||
"radio.setTransmitSerialNumber": "無線で、デバイスのシリアル番号を送信するかどうかを指定できます。"
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
{
|
||||
"radio.onDataPacketReceived|block": "無線で受信したとき",
|
||||
"radio.sendNumber|block": "無線で数字 %value を送信",
|
||||
"radio.sendNumber|block": "無線で数字を送信 %value",
|
||||
"radio.sendString|block": "無線で文字列を送信 %msg",
|
||||
"radio.sendValue|block": "無線で送信 | %name |= %value",
|
||||
"radio.setGroup|block": "無線のグループを設定 %ID",
|
||||
"radio.setTransmitPower|block": "無線の送信パワー %power",
|
||||
"radio.setTransmitSerialNumber|block": "無線でシリアル番号を送信 %transmit",
|
||||
"{id:category}Radio": "無線"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.9.16",
|
||||
"version": "0.9.26",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -36,6 +36,6 @@
|
||||
"semantic-ui-less": "^2.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.11.45"
|
||||
"pxt-core": "0.11.51"
|
||||
}
|
||||
}
|
||||
|
@ -333,7 +333,7 @@
|
||||
"coloredToolbox": true,
|
||||
"monacoToolbox": true,
|
||||
"hasAudio": true,
|
||||
"blocklyOptions": {
|
||||
"blocklyOptions": {
|
||||
"grid": {
|
||||
"spacing": 45,
|
||||
"length": 7,
|
||||
|
BIN
sim/public/blocks/iconnames/angry.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/asleep.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/butterfly.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sim/public/blocks/iconnames/chessboard.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/confused.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/cow.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/diamond.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/duck.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/eigthnote.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/fabulous.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/ghost.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/giraffe.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/happy.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/heart.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/house.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/lefttriangle.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/meh.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/no.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/pitchfork.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sim/public/blocks/iconnames/quarternote.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/rabbit.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/rollerskate.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/sad.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/silly.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/skull.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/smalldiamond.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/smallheart.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/smallsquare.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/snake.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/square.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/stickfigure.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/surprised.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/sword.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/target.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/tortoise.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sim/public/blocks/iconnames/triangle.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sim/public/blocks/iconnames/tshirt.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sim/public/blocks/iconnames/umbrella.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sim/public/blocks/iconnames/yes.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
@ -562,8 +562,9 @@ namespace pxsim.visuals {
|
||||
const x = state.accelerometerState.accelerometer.getX();
|
||||
const y = -state.accelerometerState.accelerometer.getY();
|
||||
const af = 8 / 1023;
|
||||
const s = 1 - Math.min(0.1, Math.pow(Math.max(Math.abs(x), Math.abs(y)) / 1023, 2) / 35);
|
||||
|
||||
this.element.style.transform = "perspective(30em) rotateX(" + y * af + "deg) rotateY(" + x * af + "deg)"
|
||||
this.element.style.transform = `perspective(30em) rotateX(${y * af}deg) rotateY(${x * af}deg) scale(${s}, ${s})`
|
||||
this.element.style.perspectiveOrigin = "50% 50% 50%";
|
||||
this.element.style.perspective = "30em";
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ span.blocklyTreeLabel {
|
||||
.blocklyToolboxDiv, .monacoToolboxDiv {
|
||||
background-color: white !important;
|
||||
border-left: 1px solid #ecf0f1 !important;
|
||||
box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.12), 0px 0px 2px 0px rgba(0,0,0,0.24);
|
||||
box-shadow: 4px 0px 2px -4px rgba(0,0,0,0.12), 4px 0px 2px -4px rgba(0,0,0,0.24);
|
||||
}
|
||||
|
||||
.blocklyFlyoutBackground {
|
||||
|