From 71479d0caa383cccef609a14acdf4df13ffacddf Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 15:23:54 -0800 Subject: [PATCH] adding touch button examples --- docs/examples.md | 11 +++++++++-- docs/examples/happy-unhappy.md | 19 +++++++++++++++++++ libs/core/_locales/core-jsdoc-strings.json | 4 ++-- libs/core/_locales/core-strings.json | 2 +- libs/core/buttons.ts | 22 +++++++++++----------- libs/core/screen.ts | 3 ++- 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 docs/examples/happy-unhappy.md diff --git a/docs/examples.md b/docs/examples.md index 5936e85c..42cc5677 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -4,5 +4,12 @@ Here are some fun programs for your @boardname@! ## Fun stuff - -Coming soon. \ No newline at end of file +```codecard +[ +{ + "name": "Happy unhappy", + "description": "Keep your brick entertained and happy", + "url":"/examples/happy-unhappy", + "cardType": "example" +}] +``` \ No newline at end of file diff --git a/docs/examples/happy-unhappy.md b/docs/examples/happy-unhappy.md new file mode 100644 index 00000000..4391948e --- /dev/null +++ b/docs/examples/happy-unhappy.md @@ -0,0 +1,19 @@ +# Happy unhappy + +Use a touch sensor to make the brick happy. + +```blocks +sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { + brick.showImage(images.expressionsBigSmile) +}) +sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { + brick.showImage(images.expressionsSick) +}) +loops.forever(function () { + if (sensors.touchSensor1.isTouched()) { + brick.setStatusLight(LightsPattern.Green) + } else { + brick.setStatusLight(LightsPattern.Orange) + } +}) +``` \ No newline at end of file diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 3a657732..ac170f8f 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -27,8 +27,8 @@ "brick.buttonLeft": "Left button on the EV3 Brick.", "brick.buttonRight": "Right button on the EV3 Brick.", "brick.buttonUp": "Up button on the EV3 Brick.", - "brick.pattern": "Pattern block.", - "brick.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", + "brick.lightPattern": "Pattern block.", + "brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", "brick.print": "Show text on the screen.", "brick.print|param|text": "the text to print on the screen, eg: \"Hello world\"", "brick.print|param|x": "the starting position's x coordinate, eg: 0", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index bf0ada2e..b906e2d5 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -41,7 +41,7 @@ "brick.buttonLeft|block": "left", "brick.buttonRight|block": "right", "brick.buttonUp|block": "up", - "brick.pattern|block": "%pattern", + "brick.lightPattern|block": "%pattern", "brick.print|block": "`icons.brickDisplay` print %text| at x: %x| y: %y", "brick.setPixel|block": "`icons.brickDisplay` set pixel %on| at x: %x| y: %y", "brick.setStatusLight|block": "set `icons.brickButtons` to %pattern=led_pattern", diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 4b6bd11f..22f73721 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -4,34 +4,34 @@ */ const enum LightsPattern { //% block=Off enumval=0 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern Off = 0, //% block=Green enumval=1 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern Green = 1, //% block=Red enumval=2 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern Red = 2, //% block=Orange enumval=3 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern Orange = 3, //% block="Flashing Green" enumval=4 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern GreenFlash = 4, //% block="Flashing Red" enumval=5 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern RedFlash = 5, //% block="Flashing Orange" enumval=6 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern OrangeFlash = 6, //% block="Pulsing Green" enumval=7 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern GreenPulse = 7, //% block="Pulsing Red" enumval=8 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern RedPulse = 8, //% block="Pulsing Orange" enumval=9 - //% blockIdentity=output.pattern + //% blockIdentity=brick.lightPattern OrangePulse = 9, } @@ -252,7 +252,7 @@ namespace brick { //% blockId=led_pattern block="%pattern" //% shim=TD_ID colorSecondary="#6e9a36" group="Light" //% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1 - export function pattern(pattern: LightsPattern): number { + export function lightPattern(pattern: LightsPattern): number { return pattern; } } diff --git a/libs/core/screen.ts b/libs/core/screen.ts index 710082c7..4b95db85 100644 --- a/libs/core/screen.ts +++ b/libs/core/screen.ts @@ -143,7 +143,8 @@ namespace brick { if (!image) return; image.draw(0, 0, Draw.Normal); delay = Math.max(0, delay); - loops.pause(delay); + if (delay > 0) + loops.pause(delay); } /**