Compare commits

..

17 Commits

Author SHA1 Message Date
ca61374286 0.9.27 2017-03-01 00:12:19 -08:00
37330188ef 0.9.26 2017-03-01 00:00:34 -08:00
4922a4a833 images for icons 2017-02-28 22:37:48 -08:00
9db5db5067 Update statements.md 2017-02-28 18:19:37 -08:00
75331e4297 Remove random boolean color 2017-02-28 18:12:46 -08:00
cdc0d12a98 Update faq.md 2017-02-28 18:04:52 -08:00
e08148cac6 Update classes.md 2017-02-28 17:45:42 -08:00
e947f4859b Adding support for music melody arrays (#358)
* Adding support for music melody arrays in Typescript
2017-02-28 15:23:32 -08:00
92508d2daf minor cleanup to JS docs 2017-02-28 14:58:42 -08:00
5098eaac5a 0.9.25 2017-02-28 12:15:54 -08:00
3a0d4df65c Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2017-02-28 12:15:41 -08:00
c26a81dee9 scale down simulator to avoid side cutout 2017-02-28 12:15:32 -08:00
0054dede9a Release v0.9.23 2017-02-28 10:29:02 -08:00
7e9c646684 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2017-02-28 04:57:46 -08:00
b2282b1a81 adding descriptions to code examples 2017-02-28 04:57:27 -08:00
e4c0e582d3 ui box shadow fix 2017-02-28 01:16:10 -08:00
0e18b13ea1 0.9.24 2017-02-27 22:44:52 -08:00
59 changed files with 406 additions and 55 deletions

View File

@ -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"
}]
```

View File

@ -1,3 +1,3 @@
{
"appref": "v0.9.11"
"appref": "v0.9.23"
}

View File

@ -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.

View File

@ -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)

View File

@ -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.

View File

@ -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
### ~

View File

@ -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

View File

@ -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
### ~

View File

@ -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*.

View 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)

View File

@ -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.",

View File

@ -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",

View File

@ -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;
}

View File

@ -30,83 +30,119 @@ enum IconNames {
//% 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 {
@ -456,12 +492,6 @@ namespace images {
# # # # #
. . # . .
. . # . .`;
case IconNames.Pacman: return `
. # # # #
# # # # .
# # # . .
# # # # .
. # # # #`;
case IconNames.Target: return `
. . # . .
. # # # .

119
libs/core/melodies.ts Normal file
View 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 [];
}
}
}

View File

@ -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;
}
}
}

View File

@ -26,6 +26,7 @@
"led.cpp",
"led.ts",
"music.ts",
"melodies.ts",
"pins.cpp",
"pins.ts",
"serial.cpp",

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.9.23",
"version": "0.9.27",
"description": "micro:bit target for PXT",
"keywords": [
"JavaScript",

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -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";
}

View File

@ -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 {