Add more snippet types for better detection

This commit is contained in:
Thomas Denney 2016-08-09 16:52:24 +01:00
parent 9fd2a3a3e6
commit 9ebd9d4f04
12 changed files with 29 additions and 31 deletions

View File

@ -48,21 +48,21 @@ The micro:bits *scheduler* provides the capability to concurrently execute di
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses.
```
```blocks
export function countButtonPresses() {
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
}
```
The program above contains three statements that execute in order from top to bottom. The first statement
```
```blocks
input.onButtonPressed(Button.A, () => {
count = count + 1
})
@ -70,7 +70,7 @@ input.onButtonPressed(Button.A, () => {
informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one. The second statement
```
```blocks
basic.forever(() => {
basic.showNumber(count, 150)
})
@ -78,7 +78,7 @@ basic.forever(() => {
queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
```
```blocks
count = 0
```
@ -128,7 +128,7 @@ Through this example, we have seen that the micro:bit scheduler enables you to c
As a result, you can easily add a new capability to the micro:bit by just adding a new subprogram. For example, if you want to add a reset feature to the counter program, all you need to do is add a new event handler for a press of button B that sets the global variable "count" to zero, as shown below:
```
```blocks
export function countButtonPressesWithReset() {
input.onButtonPressed(Button.A, () => {
count = count + 1

View File

@ -34,8 +34,7 @@ Let's code the third part of Happy Birthday!
To do this, you need to add blocks after the last line of the `play` blocks. We want to continue to adding musical chords with the `play` block. Then insert the appropriate chord blocks `G`, `E`, `C`, `B`, `A` to complete the third part of the song. Modify your code so that your code looks like this.
``` blocks
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
@ -57,8 +56,7 @@ music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
basic.pause(100);
```
```
* click *run * to see if the code works as expected.

View File

@ -23,7 +23,7 @@ In this animation, each row is 15 spaces wide because
there are three frames in the animation, and each frame is
five spaces wide, just like the screen on the BBC micro:bit.
```
```blocks
basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
@ -47,7 +47,7 @@ In this animation, each row is 30 spaces wide because
there are six frames in the animation, and each frame is
five spaces wide, just like the screen.
```
```blocks
basic.showAnimation(`
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .

View File

@ -23,7 +23,7 @@ devices.onSignalStrengthChanged(() => {})
Display the signal strength on screen:
```
```blocks
devices.onSignalStrengthChanged(() => {
basic.showNumber(devices.signalStrength(), 150)
})

View File

@ -6,7 +6,7 @@ Turn off all the pixels in an [Image](/reference/images/image).
### JavaScript
```
```sig
export function clear(img: micro_bit.Image)
```
@ -18,7 +18,7 @@ export function clear(img: micro_bit.Image)
The following example turns off the pixels of `img` when the A input button is pressed:
```
```blocks
let img = images.createImage(`
. . . . .
. # # # .

View File

@ -2,12 +2,12 @@
Reports the x position of a sprite on the LED screen
```
```sig
export function x(_this: micro_bitSprites.LedSprite) : number
```
Reports the y position of a sprite on the LED screen
```
```sig
export function y(_this: micro_bitSprites.LedSprite) : number
```

View File

@ -4,24 +4,24 @@ Reports the x or y position, the current direction of a sprite, or the brightne
Reports the x position of a sprite on the LED screen
```
```sig
export function x(_this: micro_bitSprites.LedSprite) : number
```
Reports the y position of a sprite on the LED screen
```
```sig
export function y(_this: micro_bitSprites.LedSprite) : number
```
Reports the brightness of a sprite on the LED screen
```
```sig
export function brightness(_this: micro_bitSprites.LedSprite) : number
```
Reports the current direction of a sprite on the LED screen
```
```sig
export function direction(_this: micro_bitSprites.LedSprite) : number
```

View File

@ -6,7 +6,7 @@ Get the state of a pixel in an [Image](/reference/images/image).
### JavaScript
```
```sig
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean
```
@ -29,7 +29,7 @@ This example gets the state of pixel `0, 0` in the `img` variable:
### ~hide
```
```blocks
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
@ -41,7 +41,7 @@ let img = images.createImage(`
### ~
```
```blocks
let state = img.pixel(0, 0)
```

View File

@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
### JavaScript
```
```sig
export function showFrame(img: micro_bit.Image, frame: number)
```
@ -20,7 +20,7 @@ The `show frame` function is the same as [plot frame](/reference/images/plot-fra
### Example
```
```blocks
let img = images.createImage(`
# . . . # # . . . #
. # . # . . # # # .

View File

@ -20,7 +20,7 @@ The following example gets the width of `img` and stores it in the `w` variable:
### ~hide
```
```blocks
let img = images.createImage(`
. . # . . . . . . .
. # . # . . . # . .
@ -32,7 +32,7 @@ let img = images.createImage(`
### ~
```
```blocks
let w = img.width()
```
@ -40,7 +40,7 @@ let w = img.width()
The following example uses the `width` function with a [for](/blocks/loops/for) loop to show each image frame on the screen:
```
```blocks
let img2 = images.createImage(`
. . # . . . # # # # . # # # .
. # # . . . . . . # . . . # .

View File

@ -13,7 +13,7 @@ pins.analogPitch(440, 300)
### Example
```
```blocks
pins.analogSetPitchPin("P0")
let frequency1 = 440
let duration = 1000

View File

@ -12,7 +12,7 @@ pins.analogSetPitchPin(AnalogPin.P0)
### Example
```
```blocks
pins.analogSetPitchPin(AnalogPin.P0)
let frequency = 440
let duration = 1000