diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 27c1e181..78d3dc98 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -69,6 +69,12 @@ * [clear counts](/reference/motors/motor/clear-counts) * [stop all motors](/reference/motors/stop-all-motors) * [Sensors](/reference/sensors) - * [angle](/reference/sensors/gyro/angle) - * [rate](/reference/sensors/gyro/rate) - * [reset](/reference/sensors/gyro/reset) \ No newline at end of file + * [Touch](/reference/sensors/touch-sensor) + * [on event](/reference/sensors/touch-sensor/on-event) + * [pause until](/reference/sensors/touch-sensor/pause-until) + * [is pressed](/reference/sensors/touch-sensor/is-pressed) + * [was pressed](/reference/sensors/touch-sensor/was-pressed) + * [Gyro](/reference/sensors/gyro) + * [angle](/reference/sensors/gyro/angle) + * [rate](/reference/sensors/gyro/rate) + * [reset](/reference/sensors/gyro/reset) \ No newline at end of file diff --git a/docs/reference/sensors.md b/docs/reference/sensors.md index 12f89964..befa367c 100644 --- a/docs/reference/sensors.md +++ b/docs/reference/sensors.md @@ -1,5 +1,14 @@ # Sensors +## Touch + +```cards +sensors.touch1.onEvent(ButtonEvent.Pressed, function () {}) +sensors.touch1.pauseUntil(ButtonEvent.Pressed) +sensors.touch1.wasPressed() +sensors.touch1.isPressed() +``` + ## Gyro ```cards diff --git a/libs/gyro-sensor/docs/reference/sensors/gyro.md b/libs/gyro-sensor/docs/reference/sensors/gyro.md new file mode 100644 index 00000000..5712c739 --- /dev/null +++ b/libs/gyro-sensor/docs/reference/sensors/gyro.md @@ -0,0 +1,13 @@ +# Gyro sensor + +```cards +sensors.gyro1.angle(); +sensors.gyro1.rate(); +sensors.gyro1.reset(); +``` + +## See Also + +[angle](/reference/sensors/gyro/angle), +[rate](/reference/sensors/gyro/rate), +[reset](/reference/sensors/gyro/reset) 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 index e75a02a2..2d68ec5c 100644 --- a/libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/is-pressed.md @@ -1,5 +1,18 @@ # is Pressed +Check to see if a touch sensor is currently pressed or not. + +```sig +sensors.touch1.isPressed() +``` +## Returns + +* a [boolean](/types/boolean) value that is `true` if the sensor is currently pressed. It's `false` if the sensor is not pressed. + +## Example + +If the touch sensor ``touch 1`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`. + ```blocks loops.forever(function () { if (sensors.touch1.isPressed()) { @@ -8,4 +21,8 @@ loops.forever(function () { brick.setStatusLight(StatusLight.Orange) } }) -``` \ No newline at end of file +``` + +## See also + +[was pressed](/reference/sensors/touch-sensor/was-pressed), [on event](/reference/sensors/touch-sensor/on-event) \ 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 index 6b87172b..15db5a3e 100644 --- a/libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/on-event.md @@ -1,16 +1,33 @@ -# On Event +# on Event + +Run some code when a touch sensor is pressed, bumped, or released. ```sig -sensors.touch1.onEvent(ButtonEvent.Released, function () { }) +sensors.touch1.onEvent(ButtonEvent.Bumped, function () { + +}); ``` -# Parameters +## Parameters -## Examples +* **ev**: the touch sensor action to run some code for. The the touch actions (events) are: +> * ``pressed``: the sensor was pressed, or pressed and released +> * ``bumped``: the sensor was just bumped +> * ``released``: the sensor was just released +* **body**: the code you want to run when something happens to the touch sensor. +## Example + +Check for an event on touch sensor ``touch 1``. Put an expression on the screen when the senosr is released. ```blocks sensors.touch1.onEvent(ButtonEvent.Released, function () { brick.showImage(images.expressionsSick) }) ``` + +### See also + +[is pressed](/reference/sensors/touch-sensor/is-pressed), +[was pressed](/reference/sensors/touch-sensor/was-pressed), +[pause until](/reference/sensors/touch-sensor/pause-until) diff --git a/libs/touch-sensor/docs/reference/sensors/touch-sensor/pause-until.md b/libs/touch-sensor/docs/reference/sensors/touch-sensor/pause-until.md new file mode 100644 index 00000000..22b99b9d --- /dev/null +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/pause-until.md @@ -0,0 +1,37 @@ +# pause Until + +Make your program wait until an event at a touch sensor happens. + +```sig +sensors.touch1.pauseUntil(ButtonEvent.Bumped); +``` + +## Parameters + +* **ev**: the touch sensor action to wait for. The the touch actions (events) are: +> * ``pressed``: the sensor was pressed, or pressed and released +> * ``bumped``: the sensor was just bumped +> * ``released``: the sensor was just released + +## Example + +Wait for a bump to touch sensor `touch 1` before continuing with displaying a message on the screen. + +```blocks +let waitTime = 0; +brick.showString("We're going to wait", 1); +brick.showString("for you to bump the", 2); +brick.showString("touch sensor on port 1", 3); +waitTime = control.millis(); +sensors.touch1.pauseUntil(ButtonEvent.Bumped); +brick.clearScreen(); +if (control.millis() - waitTime > 5000) { + brick.showString("Ok, that took awhile!", 1) +} else { + brick.showString("Ah, you let go!", 1) +} +``` + +## See also + +[on event](/reference/sensors/touch-sensor/on-event) \ No newline at end of file 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 index 37a0f921..8560a3d2 100644 --- a/libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md +++ b/libs/touch-sensor/docs/reference/sensors/touch-sensor/was-pressed.md @@ -1,5 +1,21 @@ # was Pressed +See if a touch sensor was pressed since the last time it was checked. + +```sig +sensors.touch1.wasPressed() +``` + +If a touch sensor was pressed, then that event is remembered. Once you check if a touch sensor **was pressed**, that status is set back to `false`. If you check again before the sensor is touched another time, the **was pressed** status is `false`. Only when the sensor is touched will the **was pressed** status go to `true`. + +## Returns + +* a [boolean](/types/boolean) value that is `true` if the sensor is was pressed before. It's `false` if the sensor was not pressed. + +## Example + +If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`. + ```blocks loops.forever(function () { if (sensors.touch1.wasPressed()) { @@ -7,5 +23,10 @@ loops.forever(function () { } else { brick.setStatusLight(StatusLight.Orange) } + loops.pause(500) }) -``` \ No newline at end of file +``` + +## See also + +[is pressed](/reference/sensors/touch-sensor/is-pressed), [on event](/reference/sensors/touch-sensor/on-event) \ No newline at end of file diff --git a/libs/touch-sensor/touch.ts b/libs/touch-sensor/touch.ts index 9923874d..864ee76a 100644 --- a/libs/touch-sensor/touch.ts +++ b/libs/touch-sensor/touch.ts @@ -29,7 +29,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-sensor/on-event + //% help=sensors/touch-sensor/on-event //% blockId=touchEvent block="on %sensor|%event" //% parts="touch" //% blockNamespace=sensors @@ -45,7 +45,7 @@ namespace sensors { * @param sensor the touch sensor that needs to be clicked or used * @param event the kind of button gesture that needs to be detected */ - //% help=input/touch-sensor/pause-until + //% help=sensors/touch-sensor/pause-until //% blockId=touchWaitUntil block="pause until %sensor|%event" //% parts="touch" //% blockNamespace=sensors @@ -60,7 +60,7 @@ namespace sensors { * Check if touch sensor is touched. * @param sensor the port to query the request */ - //% help=input/touch-sensor/is-pressed + //% help=sensors/touch-sensor/is-pressed //% block="%sensor|is pressed" //% blockId=touchIsPressed //% parts="touch" @@ -76,7 +76,7 @@ namespace sensors { * 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 + //% help=sensors/touch-sensor/was-pressed //% block="%sensor|was pressed" //% blockId=touchWasPressed //% parts="touch"