support for interval in "show icon", "show arrow"

This commit is contained in:
Peli de Halleux 2017-05-25 16:52:52 -07:00
parent 0d4c5e9630
commit fb5a8cf64d
5 changed files with 45 additions and 21 deletions

View File

@ -6,6 +6,12 @@ Shows the selected arrow on the LED screen
basic.showArrow(ArrowNames.North)
```
### Parameters
* ``direction``, the identifier of the arrow to display
* ``interval`` (optional), the time to display in milliseconds. default is 400.
### Example
This program shows all eight arrows.

View File

@ -6,6 +6,11 @@ Shows the selected icon on the LED screen
basic.showIcon(IconNames.Heart)
```
### Parameters
* ``icon``, the identifier of the icon to display
* ``interval`` (optional), the time to display in milliseconds. default is 400.
### Example
This program shows a happy face and then a sad face with the ``show icon`` function, with a one second pause in between.

View File

@ -36,7 +36,12 @@
"basic.showAnimation": "Shows a sequence of LED screens as an animation.",
"basic.showAnimation|param|interval": "time in milliseconds between each redraw",
"basic.showAnimation|param|leds": "pattern of LEDs to turn on/off",
"basic.showArrow": "Shows an arrow on screent",
"basic.showArrow|param|direction": "the direction of the arrow",
"basic.showArrow|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showIcon": "Draws the selected icon on the LED screen",
"basic.showIcon|param|icon": "the predifined icon id",
"basic.showIcon|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showLeds": "Draws an image on the LED screen.",
"basic.showLeds|param|interval": "time in milliseconds to pause after drawing",
"basic.showLeds|param|leds": "the pattern of LED to turn on/off",

View File

@ -191,6 +191,7 @@
"basic.clearScreen|block": "clear screen",
"basic.forever|block": "forever",
"basic.pause|block": "pause (ms) %pause",
"basic.showArrow|block": "show arrow %i=device_arrow",
"basic.showIcon|block": "show icon %i",
"basic.showLeds|block": "show leds",
"basic.showNumber|block": "show|number %number",

View File

@ -171,6 +171,8 @@ namespace basic {
/**
* Draws the selected icon on the LED screen
* @param icon the predifined icon id
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
//% weight=90 blockGap=8
//% blockId=basic_show_icon
@ -180,20 +182,25 @@ namespace basic {
//% i.fieldEditor="gridpicker"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
//% i.fieldOptions.itemColour="black" i.fieldOptions.tooltips="true"
export function showIcon(icon: IconNames) {
export function showIcon(icon: IconNames, interval = 600) {
let res = images.iconImage(icon)
res.showImage(0)
res.showImage(0, interval)
}
/**
* Shows an arrow on screent
* @param direction the direction of the arrow
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
//% weight=50 blockGap=8
//% blockId=basic_show_arrow
//% blockId=basic_show_arrow
//% 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)
export function showArrow(direction: number, interval = 600) {
let res = images.arrowImage(direction)
res.showImage(0, interval)
}
}
@ -202,8 +209,8 @@ namespace images {
//% weight=50 blockGap=8
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i : ArrowNames): Image {
switch(i) {
export function arrowImage(i: ArrowNames): Image {
switch (i) {
// compass directions
case ArrowNames.North: return images.createImage(`
. . # . .
@ -217,7 +224,7 @@ namespace images {
. . # . #
. # . . .
# . . . .`);
case ArrowNames.East: return images.createImage(`
case ArrowNames.East: return images.createImage(`
. . # . .
. . . # .
# # # # #
@ -253,34 +260,34 @@ namespace images {
# . # . .
. . . # .
. . . . #`);
default: return images.createImage(`
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`);
}
}
}
//% weight=50 blockGap=8
//% blockId=builtin_image block="icon image %i"
export function iconImage(i: IconNames): Image {
switch (i) {
case IconNames.Heart : return images.createImage(`
switch (i) {
case IconNames.Heart: return images.createImage(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
case IconNames.SmallHeart : return images.createImage(`
case IconNames.SmallHeart: return images.createImage(`
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`);
//faces
//faces
case IconNames.Happy: return images.createImage(`
. . . . .
. # . # .
@ -396,7 +403,7 @@ namespace images {
. . # . .
# # . # .
# # . . #`);
// The following images were designed by Abbie Brooks.
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return images.createImage(`
# # . # #
# # # # #
@ -475,7 +482,7 @@ namespace images {
. # . # .
. # # # .
. . . . .`);
// animals
// animals
case IconNames.Rabbit: return images.createImage(`
# . # . .
# . # . .
@ -488,7 +495,7 @@ namespace images {
# # # # #
. # # # .
. . # . .`);
// musical notes
// musical notes
case IconNames.QuarterNote: return images.createImage(`
. . # . .
. . # . .
@ -501,7 +508,7 @@ namespace images {
. . # . #
# # # . .
# # # . .`);
// other icons
// other icons
case IconNames.Pitchfork: return images.createImage(`
# . # . #
# . # . #
@ -514,7 +521,7 @@ namespace images {
# # . # #
. # # # .
. . # . .`);
default: return images.createImage(`
default: return images.createImage(`
. . . . .
. . . . .
. . . . .