Touch sensor doc fill-in (#320)
This commit is contained in:
parent
1d83d6c40e
commit
6f539de2d2
@ -69,6 +69,12 @@
|
|||||||
* [clear counts](/reference/motors/motor/clear-counts)
|
* [clear counts](/reference/motors/motor/clear-counts)
|
||||||
* [stop all motors](/reference/motors/stop-all-motors)
|
* [stop all motors](/reference/motors/stop-all-motors)
|
||||||
* [Sensors](/reference/sensors)
|
* [Sensors](/reference/sensors)
|
||||||
* [angle](/reference/sensors/gyro/angle)
|
* [Touch](/reference/sensors/touch-sensor)
|
||||||
* [rate](/reference/sensors/gyro/rate)
|
* [on event](/reference/sensors/touch-sensor/on-event)
|
||||||
* [reset](/reference/sensors/gyro/reset)
|
* [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)
|
@ -1,5 +1,14 @@
|
|||||||
# Sensors
|
# Sensors
|
||||||
|
|
||||||
|
## Touch
|
||||||
|
|
||||||
|
```cards
|
||||||
|
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {})
|
||||||
|
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||||
|
sensors.touch1.wasPressed()
|
||||||
|
sensors.touch1.isPressed()
|
||||||
|
```
|
||||||
|
|
||||||
## Gyro
|
## Gyro
|
||||||
|
|
||||||
```cards
|
```cards
|
||||||
|
13
libs/gyro-sensor/docs/reference/sensors/gyro.md
Normal file
13
libs/gyro-sensor/docs/reference/sensors/gyro.md
Normal file
@ -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)
|
@ -1,5 +1,18 @@
|
|||||||
# is Pressed
|
# 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
|
```blocks
|
||||||
loops.forever(function () {
|
loops.forever(function () {
|
||||||
if (sensors.touch1.isPressed()) {
|
if (sensors.touch1.isPressed()) {
|
||||||
@ -8,4 +21,8 @@ loops.forever(function () {
|
|||||||
brick.setStatusLight(StatusLight.Orange)
|
brick.setStatusLight(StatusLight.Orange)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[was pressed](/reference/sensors/touch-sensor/was-pressed), [on event](/reference/sensors/touch-sensor/on-event)
|
@ -1,16 +1,33 @@
|
|||||||
# On Event
|
# on Event
|
||||||
|
|
||||||
|
Run some code when a touch sensor is pressed, bumped, or released.
|
||||||
|
|
||||||
```sig
|
```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
|
```blocks
|
||||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||||
brick.showImage(images.expressionsSick)
|
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)
|
||||||
|
@ -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)
|
@ -1,5 +1,21 @@
|
|||||||
# was Pressed
|
# 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
|
```blocks
|
||||||
loops.forever(function () {
|
loops.forever(function () {
|
||||||
if (sensors.touch1.wasPressed()) {
|
if (sensors.touch1.wasPressed()) {
|
||||||
@ -7,5 +23,10 @@ loops.forever(function () {
|
|||||||
} else {
|
} else {
|
||||||
brick.setStatusLight(StatusLight.Orange)
|
brick.setStatusLight(StatusLight.Orange)
|
||||||
}
|
}
|
||||||
|
loops.pause(500)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[is pressed](/reference/sensors/touch-sensor/is-pressed), [on event](/reference/sensors/touch-sensor/on-event)
|
@ -29,7 +29,7 @@ namespace sensors {
|
|||||||
* @param event the kind of button gesture that needs to be detected
|
* @param event the kind of button gesture that needs to be detected
|
||||||
* @param body code to run when the event is raised
|
* @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"
|
//% blockId=touchEvent block="on %sensor|%event"
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
@ -45,7 +45,7 @@ namespace sensors {
|
|||||||
* @param sensor the touch sensor that needs to be clicked or used
|
* @param sensor the touch sensor that needs to be clicked or used
|
||||||
* @param event the kind of button gesture that needs to be detected
|
* @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"
|
//% blockId=touchWaitUntil block="pause until %sensor|%event"
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
@ -60,7 +60,7 @@ namespace sensors {
|
|||||||
* Check if touch sensor is touched.
|
* Check if touch sensor is touched.
|
||||||
* @param sensor the port to query the request
|
* @param sensor the port to query the request
|
||||||
*/
|
*/
|
||||||
//% help=input/touch-sensor/is-pressed
|
//% help=sensors/touch-sensor/is-pressed
|
||||||
//% block="%sensor|is pressed"
|
//% block="%sensor|is pressed"
|
||||||
//% blockId=touchIsPressed
|
//% blockId=touchIsPressed
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
@ -76,7 +76,7 @@ namespace sensors {
|
|||||||
* Check if touch sensor is touched since it was last checked.
|
* Check if touch sensor is touched since it was last checked.
|
||||||
* @param sensor the port to query the request
|
* @param sensor the port to query the request
|
||||||
*/
|
*/
|
||||||
//% help=input/touch-sensor/was-pressed
|
//% help=sensors/touch-sensor/was-pressed
|
||||||
//% block="%sensor|was pressed"
|
//% block="%sensor|was pressed"
|
||||||
//% blockId=touchWasPressed
|
//% blockId=touchWasPressed
|
||||||
//% parts="touch"
|
//% parts="touch"
|
||||||
|
Loading…
Reference in New Issue
Block a user