From 71479d0caa383cccef609a14acdf4df13ffacddf Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 15:23:54 -0800 Subject: [PATCH 1/5] 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); } /** From b57ae5d5888ba7ed2ee96c62f52803bff4b2e960 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 15:33:43 -0800 Subject: [PATCH 2/5] implement wasPressed --- libs/core/buttons.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 22f73721..2e04f419 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -68,6 +68,7 @@ namespace brick { _update(curr: boolean) { if (this._isPressed == curr) return this._isPressed = curr + if (curr) this._wasPressed = true; if (curr) { this.downTime = control.millis() control.raiseEvent(this._id, ButtonEvent.Down) From 580b40876c2efe6bbf56ee7afe240111fb86f664 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 16:02:04 -0800 Subject: [PATCH 3/5] fixing bumped --- libs/core/buttons.ts | 8 ++++---- libs/core/core.ts | 2 +- libs/core/input.ts | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 2e04f419..348fdc13 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -68,15 +68,15 @@ namespace brick { _update(curr: boolean) { if (this._isPressed == curr) return this._isPressed = curr - if (curr) this._wasPressed = true; if (curr) { + this._wasPressed = true; this.downTime = control.millis() control.raiseEvent(this._id, ButtonEvent.Down) } else { control.raiseEvent(this._id, ButtonEvent.Up) - let delta = control.millis() - this.downTime - control.raiseEvent(this._id, ButtonEvent.Click) - //control.raiseEvent(this._id, delta > 500 ? ButtonEvent.LongClick : ButtonEvent.Click) + const delta = control.millis() - this.downTime; + if (delta < 500) + control.raiseEvent(this._id, ButtonEvent.Click) } } diff --git a/libs/core/core.ts b/libs/core/core.ts index 32d804bf..a40184bf 100644 --- a/libs/core/core.ts +++ b/libs/core/core.ts @@ -10,7 +10,7 @@ namespace control { this._id = id } - getId() { + id() { return this._id; } } diff --git a/libs/core/input.ts b/libs/core/input.ts index 6f8c3ff9..894c9203 100644 --- a/libs/core/input.ts +++ b/libs/core/input.ts @@ -132,26 +132,26 @@ namespace sensors.internal { } export class Sensor extends control.Component { - protected port: number // this is 0-based + protected _port: number // this is 0-based constructor(port_: number) { super() if (!(1 <= port_ && port_ <= DAL.NUM_INPUTS)) control.panic(120) - this.port = port_ - 1 + this._port = port_ - 1 init() - sensorInfos[this.port].sensors.push(this) + sensorInfos[this._port].sensors.push(this) } _activated() { } // 1-based - getPort() { - return this.port + 1 + port() { + return this._port + 1 } isActive() { - return sensorInfos[this.port].sensor == this + return sensorInfos[this._port].sensor == this } _query() { @@ -173,7 +173,7 @@ namespace sensors.internal { _readPin6() { if (!this.isActive()) return 0 - return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this.port) + return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this._port) } } @@ -202,18 +202,18 @@ namespace sensors.internal { if (!this.isActive()) return if (this.realmode != this.mode) { this.realmode = v - setUartMode(this.port, v) + setUartMode(this._port, v) } } getBytes(): Buffer { - return getUartBytes(this.isActive() ? this.port : -1) + return getUartBytes(this.isActive() ? this._port : -1) } getNumber(fmt: NumberFormat, off: number) { if (!this.isActive()) return 0 - return getUartNumber(fmt, off, this.port) + return getUartNumber(fmt, off, this._port) } } From f22edac84d228332c3ab39d9e413b35bcead0b03 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 16:11:15 -0800 Subject: [PATCH 4/5] moving touch stuff into separate projects --- libs/core/_locales/core-jsdoc-strings.json | 4 --- libs/core/_locales/core-strings.json | 10 -------- libs/core/pxt.json | 1 - libs/ev3/pxt.json | 3 ++- libs/touch-sensor/README.md | 3 +++ .../_locales/touch-sensor-jsdoc-strings.json | 7 ++++++ .../_locales/touch-sensor-strings.json | 14 +++++++++++ libs/touch-sensor/pxt.json | 15 +++++++++++ libs/touch-sensor/test.ts | 8 ++++++ libs/{core => touch-sensor}/touch.ts | 25 +++++++++++++++---- pxtarget.json | 1 + 11 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 libs/touch-sensor/README.md create mode 100644 libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json create mode 100644 libs/touch-sensor/_locales/touch-sensor-strings.json create mode 100644 libs/touch-sensor/pxt.json create mode 100644 libs/touch-sensor/test.ts rename libs/{core => touch-sensor}/touch.ts (75%) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index ac170f8f..5e9221e1 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -14,7 +14,6 @@ "MMap.setNumber": "Write a number in specified format in the buffer.", "MMap.slice": "Read a range of bytes into a buffer.", "MMap.write": "Perform write(2) on the underlaying file", - "TouchSensorEvent": "Touch sensor interactions", "brick.Button": "Generic button class, for device buttons and sensors.", "brick.Button.isPressed": "Check if button is currently pressed or not.", "brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.", @@ -86,9 +85,6 @@ "sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down", "sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised", "sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.", - "sensors.TouchSensor.isTouched": "Check if touch sensor is touched.", - "sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...", - "sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised", "sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters", "sensors.UltraSonicSensor.on": "Registers code to run when the given color is close", "sensors.UltraSonicSensor.on|param|handler": "the code to run when detected", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index b906e2d5..1ec3eb36 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -27,9 +27,6 @@ "Output.B|block": "B", "Output.C|block": "C", "Output.D|block": "D", - "TouchSensorEvent.Bumped|block": "bumped", - "TouchSensorEvent.Pressed|block": "pressed", - "TouchSensorEvent.Released|block": "released", "UltrasonicSensorEvent.ObjectDetected|block": "object detected", "UltrasonicSensorEvent.ObjectNear|block": "object near", "brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed", @@ -82,8 +79,6 @@ "sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed", "sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event", "sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed", - "sensors.TouchSensor.isTouched|block": "`icons.touchSensor` %sensor|is touched", - "sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event", "sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance", "sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event", "sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event", @@ -104,10 +99,6 @@ "sensors.remoteButtonCenter|block": "center", "sensors.remoteButtonTopLeft|block": "top-left", "sensors.remoteButtonTopRight|block": "top-right", - "sensors.touchSensor1|block": "1", - "sensors.touchSensor2|block": "2", - "sensors.touchSensor3|block": "3", - "sensors.touchSensor4|block": "4", "sensors.ultrasonic1|block": "1", "sensors.ultrasonic2|block": "2", "sensors.ultrasonic3|block": "3", @@ -132,6 +123,5 @@ "{id:group}Motors": "Motors", "{id:group}Remote Infrared Beacon": "Remote Infrared Beacon", "{id:group}Screen": "Screen", - "{id:group}Touch Sensor": "Touch Sensor", "{id:group}Ultrasonic Sensor": "Ultrasonic Sensor" } \ No newline at end of file diff --git a/libs/core/pxt.json b/libs/core/pxt.json index b21ee1ff..dbaf051d 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -22,7 +22,6 @@ "color.ts", "gyro.ts", "ultrasonic.ts", - "touch.ts", "shims.d.ts", "enums.d.ts", "dal.d.ts", diff --git a/libs/ev3/pxt.json b/libs/ev3/pxt.json index f9f04342..67ba5f99 100644 --- a/libs/ev3/pxt.json +++ b/libs/ev3/pxt.json @@ -8,7 +8,8 @@ "dependencies": { "base": "file:../base", "core": "file:../core", - "music": "file:../music" + "music": "file:../music", + "touch-sensor": "file:../touch-sensor" }, "public": true } diff --git a/libs/touch-sensor/README.md b/libs/touch-sensor/README.md new file mode 100644 index 00000000..18721304 --- /dev/null +++ b/libs/touch-sensor/README.md @@ -0,0 +1,3 @@ +# Touch sensor + +The library to interact with the Touch Sensor. \ No newline at end of file diff --git a/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json b/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json new file mode 100644 index 00000000..f9ab05fa --- /dev/null +++ b/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json @@ -0,0 +1,7 @@ +{ + "TouchSensorEvent": "Touch sensor interactions", + "sensors.TouchSensor.isPressed": "Check if touch sensor is touched.", + "sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...", + "sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised", + "sensors.TouchSensor.wasPressed": "Check if touch sensor is touched since it was last checked." +} \ No newline at end of file diff --git a/libs/touch-sensor/_locales/touch-sensor-strings.json b/libs/touch-sensor/_locales/touch-sensor-strings.json new file mode 100644 index 00000000..34887021 --- /dev/null +++ b/libs/touch-sensor/_locales/touch-sensor-strings.json @@ -0,0 +1,14 @@ +{ + "TouchSensorEvent.Bumped|block": "bumped", + "TouchSensorEvent.Pressed|block": "pressed", + "TouchSensorEvent.Released|block": "released", + "sensors.TouchSensor.isPressed|block": "`icons.touchSensor` %sensor|is pressed", + "sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event", + "sensors.TouchSensor.wasPressed|block": "`icons.touchSensor` %sensor|was pressed", + "sensors.touchSensor1|block": "1", + "sensors.touchSensor2|block": "2", + "sensors.touchSensor3|block": "3", + "sensors.touchSensor4|block": "4", + "{id:category}Sensors": "Sensors", + "{id:group}Touch Sensor": "Touch Sensor" +} \ No newline at end of file diff --git a/libs/touch-sensor/pxt.json b/libs/touch-sensor/pxt.json new file mode 100644 index 00000000..f757c1e3 --- /dev/null +++ b/libs/touch-sensor/pxt.json @@ -0,0 +1,15 @@ +{ + "name": "touch-sensor", + "description": "Touch Sensor support", + "files": [ + "README.md", + "touch.ts" + ], + "testFiles": [ + "test.ts" + ], + "public": true, + "dependencies": { + "core": "file:../core" + } +} \ No newline at end of file diff --git a/libs/touch-sensor/test.ts b/libs/touch-sensor/test.ts new file mode 100644 index 00000000..082d6140 --- /dev/null +++ b/libs/touch-sensor/test.ts @@ -0,0 +1,8 @@ +sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { +}) +sensors.touchSensor2.onEvent(TouchSensorEvent.Bumped, function () { +}) +sensors.touchSensor3.onEvent(TouchSensorEvent.Released, function () { +}) +sensors.touchSensor4.isPressed(); +sensors.touchSensor4.wasPressed(); diff --git a/libs/core/touch.ts b/libs/touch-sensor/touch.ts similarity index 75% rename from libs/core/touch.ts rename to libs/touch-sensor/touch.ts index 119bc80d..bf1a0858 100644 --- a/libs/core/touch.ts +++ b/libs/touch-sensor/touch.ts @@ -41,7 +41,7 @@ namespace sensors { * @param event the kind of button gesture that needs to be detected * @param body code to run when the event is raised */ - //% help=input/touch/on-event + //% help=input/touch-sensor/on-event //% blockId=touchEvent block="on `icons.touchSensor` %sensor|%event" //% parts="touch" //% blockNamespace=sensors @@ -55,16 +55,31 @@ namespace sensors { * Check if touch sensor is touched. * @param sensor the port to query the request */ - //% help=input/touch/is-touched - //% block="`icons.touchSensor` %sensor|is touched" - //% blockId=touchIsTouched + //% help=input/touch-sensor/is-pressed + //% block="`icons.touchSensor` %sensor|is pressed" + //% blockId=touchIsPressed //% parts="touch" //% blockNamespace=sensors //% weight=81 blockGap=8 //% group="Touch Sensor" - isTouched() { + isPressed() { return this.button.isPressed(); } + + /** + * Check if touch sensor is touched since it was last checked. + * @param sensor the port to query the request + */ + //% help=input/touch-sensor/was-pressed + //% block="`icons.touchSensor` %sensor|was pressed" + //% blockId=touchWasPressed + //% parts="touch" + //% blockNamespace=sensors + //% weight=81 blockGap=8 + //% group="Touch Sensor" + wasPressed() { + return this.button.wasPressed(); + } } //% whenUsed block="1" weight=95 fixedInstance diff --git a/pxtarget.json b/pxtarget.json index 3c894543..9ba18d32 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -10,6 +10,7 @@ "libs/base", "libs/core", "libs/music", + "libs/touch-sensor", "libs/ev3" ], "simulator": { From 7e502b1749cc0cfb3b90fdca44376d18e8a407ee Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Nov 2017 16:24:22 -0800 Subject: [PATCH 5/5] adding bare docs --- docs/examples/happy-unhappy.md | 7 ------- docs/reference.md | 6 +++++- .../docs/reference/sensors/touch-sensor.md | 15 +++++++++++++++ .../reference/sensors/touch-sensor/is-pressed.md | 11 +++++++++++ .../reference/sensors/touch-sensor/on-event.md | 16 ++++++++++++++++ .../sensors/touch-sensor/was-pressed.md | 11 +++++++++++ 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 libs/touch-sensor/docs/reference/sensors/touch-sensor.md create mode 100644 libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md create mode 100644 libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md create mode 100644 libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md diff --git a/docs/examples/happy-unhappy.md b/docs/examples/happy-unhappy.md index 4391948e..b799a97d 100644 --- a/docs/examples/happy-unhappy.md +++ b/docs/examples/happy-unhappy.md @@ -9,11 +9,4 @@ sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { 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/docs/reference.md b/docs/reference.md index ac34cc75..70f479f4 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1,3 +1,7 @@ # Reference -TODO \ No newline at end of file + + +## See Also + +[touch sensor](/reference/sensors/touch-sensor) \ No newline at end of file diff --git a/libs/touch-sensor/docs/reference/sensors/touch-sensor.md b/libs/touch-sensor/docs/reference/sensors/touch-sensor.md new file mode 100644 index 00000000..7de9e8bc --- /dev/null +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor.md @@ -0,0 +1,15 @@ +# Touch Sensor + +```cards +sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { + brick.showImage(images.expressionsBigSmile) +}) +sensors.touchSensor1.isPressed(); +sensors.touchSensor1.wasPressed(); +``` + +## See Also + +[on Event](/reference/sensors/touch-sensor/on-event), +[is pressed](reference/sensors/touch-sensor/is-pressed), +[was pressed](reference/sensors/touch-sensor/was-pressed) \ No newline at end of file diff --git a/libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md b/libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md new file mode 100644 index 00000000..7a1d9d21 --- /dev/null +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md @@ -0,0 +1,11 @@ +# is Pressed + +```blocks +loops.forever(function () { + if (sensors.touchSensor1.isPressed()) { + brick.setStatusLight(LightsPattern.Green) + } else { + brick.setStatusLight(LightsPattern.Orange) + } +}) +``` \ No newline at end of file diff --git a/libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md b/libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md new file mode 100644 index 00000000..2dedf566 --- /dev/null +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md @@ -0,0 +1,16 @@ +# On Event + +```sig +sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { }) +``` + +# Parameters + +## Examples + + +```blocks +sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { + brick.showImage(images.expressionsSick) +}) +``` diff --git a/libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md b/libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md new file mode 100644 index 00000000..70b94772 --- /dev/null +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md @@ -0,0 +1,11 @@ +# was Pressed + +```blocks +loops.forever(function () { + if (sensors.touchSensor1.wasPressed()) { + brick.setStatusLight(LightsPattern.Green) + } else { + brick.setStatusLight(LightsPattern.Orange) + } +}) +``` \ No newline at end of file