Compare commits

..

11 Commits

Author SHA1 Message Date
c157b4d922 0.0.106 2018-02-22 10:18:13 -08:00
0837123828 bumping pxt 2018-02-22 10:15:58 -08:00
e51a32b69f use full motor names (#338) 2018-02-22 10:03:25 -08:00
029066000d updated style 2018-02-22 08:28:42 -08:00
7e35abeff3 lock on 0.0.104 2018-02-22 06:54:18 -08:00
0166785c1b 0.0.105 2018-02-22 06:36:41 -08:00
ea0f6a4734 updated pxt 2018-02-22 06:36:26 -08:00
271721561d turn sample into blocks 2018-02-21 22:39:35 -08:00
ed8f8bafa7 Add 'infrared beacon' api topics (#330)
* Add 'infrared beacon' api topics

* Include note about channel selection
2018-02-21 22:35:51 -08:00
8cfb70c97b Threshold api docs - 01 (#336)
* Local commit

* Throw on more topics

* Throw in threshold topics for infrared
2018-02-21 22:35:25 -08:00
84c8e31ff5 First burst of 'color' pages (#335)
* Add 'color sensor' api topics

* Last set of edits/adds
2018-02-21 14:03:55 -08:00
36 changed files with 6628 additions and 4752 deletions

View File

@ -91,10 +91,23 @@
* [rate](/reference/sensors/gyro/rate)
* [reset](/reference/sensors/gyro/reset)
* [Ultrasonic](/reference/sensors/ultrasonic)
* [on event](/reference/sensors/ultrasonic/on-event),
* [distance](reference/sensors/ultrasonic/distance),
* [on event](/reference/sensors/ultrasonic/on-event)
* [distance](reference/sensors/ultrasonic/distance)
* [pause until](reference/sensors/ultrasonic/pause-until)
* [Infrared](/reference/sensors/infrared)
* [on event](/reference/sensors/infrared/on-event),
* [distance](reference/sensors/infrared/proximity),
* [pause until](reference/sensors/infrared/pause-until)
* [on event](/reference/sensors/infrared/on-event)
* [distance](reference/sensors/infrared/proximity)
* [pause until](reference/sensors/infrared/pause-until)
* [Infrared beacon](/reference/sensors/beacon)
* [on event](/reference/sensors/beacon/on-event)
* [pause until](/reference/sensors/beacon/pause-until)
* [is pressed](/reference/sensors/beacon/is-pressed)
* [was pressed](/reference/sensors/beacon/was-pressed)
* [set remote channel](/reference/sensors/beacon/set-remote-channel)
* [Color](/reference/sensors/color-sensor)
* [on color detected](/reference/sensors/color-sensor/on-color-detected)
* [pause for color](/reference/sensors/color-sensor/pause-for-color)
* [on light changed](/reference/sensors/color-sensor/on-light-changed)
* [pause for light](/reference/sensors/color-sensor/pause-for-light)
* [color](/reference/sensors/color-sensor/color)
* [light](/reference/sensors/color-sensor/ambient-light)

View File

@ -1,3 +1,3 @@
{
"appref": "v"
"appref": "v0.0.104"
}

View File

@ -26,7 +26,7 @@ motors.largeA.run(50, 500)
Here is how you use each different movement unit to run the motor for a fixed rotation distance.
```typescript
```blocks
// Run motor for 700 Milliseconds.
motors.largeA.run(25, 700, MoveUnit.MilliSeconds);

View File

@ -1,5 +1,17 @@
# Sensors
# Color
```cards
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {})
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {})
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
sensors.color1.color();
sensors.color1.light(LightIntensityMode.Ambient)
sensors.color(ColorSensorColor.Blue)
```
## Touch
```cards
@ -33,3 +45,13 @@ sensors.infraredSensor1.pauseUntil(null);
sensors.infraredSensor1.proximity();
```
## Infrared beacon button
```cards
sensors.remoteButtonCenter.onEvent(ButtonEvent.Pressed, function () {})
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
sensors.remoteButtonCenter.isPressed()
sensors.remoteButtonCenter.wasPressed()
sensors.infraredSensor1.setRemoteChannel(null)
```

File diff suppressed because one or more lines are too long

View File

@ -40,7 +40,7 @@ const enum ColorSensorColor {
enum LightCondition {
//% block="dark"
Dark = sensors.ThresholdState.Low,
//$ block="bright"
//% block="bright"
Bright = sensors.ThresholdState.High
}
@ -192,7 +192,7 @@ namespace sensors {
}
/**
* Waits for the given color to be detected
* Wait for the given color to be detected
* @param color the color to detect
*/
//% help=sensors/color-sensor/pause-for-light
@ -210,7 +210,7 @@ namespace sensors {
}
/**
* Measures the ambient or reflected light value from 0 (darkest) to 100 (brightest).
* Measure the ambient or reflected light value from 0 (darkest) to 100 (brightest).
* @param sensor the color sensor port
*/
//% help=sensors/color-sensor/light
@ -237,7 +237,7 @@ namespace sensors {
}
/**
* Sets a threshold value
* Set a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
@ -245,6 +245,7 @@ namespace sensors {
//% group="Threshold" blockGap=8 weight=90
//% value.min=0 value.max=100
//% sensor.fieldEditor="ports"
//% help=sensors/color-sensor/set-threshold
setThreshold(condition: LightCondition, value: number) {
if (condition == LightCondition.Dark)
this.thresholdDetector.setLowThreshold(value)
@ -253,12 +254,13 @@ namespace sensors {
}
/**
* Gets the threshold value
* Get a threshold value
* @param condition the light condition
*/
//% blockId=colorGetThreshold block="%sensor|%condition"
//% group="Threshold" blockGap=8 weight=89
//% sensor.fieldEditor="ports"
//% help=sensors/color-sensor/threshold
threshold(condition: LightCondition): number {
return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark);
}
@ -266,9 +268,10 @@ namespace sensors {
/**
* Collects measurement of the light condition and adjusts the threshold to 10% / 90%.
*/
//% blockId=colorCalibrateLight block="calibrate|%sensor|for %mode|light"
//% blockId=colorCalibrateLight block="calibrate|%sensor|for %mode"
//% group="Threshold" weight=91 blockGap=8
//% sensor.fieldEditor="ports"
//% help=sensors/color-sensor/calibrate-light
calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
this.calibrating = true; // prevent events
@ -313,11 +316,13 @@ namespace sensors {
/**
* Returns a color that the sensor can detect
* @param color the color sensed by the sensor, eg: ColorSensorColor.Red
*/
//% shim=TD_ID
//% blockId=colorSensorColor block="color %color"
//% group="Color Sensor"
//% weight=97
//% help=sensors/color
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true

View File

@ -1,16 +1,19 @@
# Color Sensor
# Color sensor
```cards
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
})
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {})
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {})
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
sensors.color1.color();
sensors.color1.ambientLight();
sensors.color1.reflectedLight();
sensors.color1.light(LightIntensityMode.Ambient)
```
## See Also
## See slso
[on color detected](/reference/sensors/color-sensor/on-color-detected),
[pause for color](/reference/sensors/color-sensor/pause-for-color),
[on light changed](/reference/sensors/color-sensor/on-light-changed),
[pause for light](/reference/sensors/color-sensor/pause-for-light),
[color](/reference/sensors/color-sensor/color),
[ambient light](/reference/sensors/color-sensor/ambient-light),
[reflected light](/reference/sensors/color-sensor/reflected-light),
[light](/reference/sensors/color-sensor/ambient-light)

View File

@ -1,4 +1,20 @@
# Ambient Light
# ambient Light
Get the amount of ambient light dectected.
```sig
sensors.color1.ambientLight()
```
The amount of ambient light measured is in the range of `0` (darkest) to `100` (brightest).
## Returns
* a [number](/types/number) that is the amount of ambiernt light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the ambient light is greater than `20`.
```blocks
forever(function () {
@ -8,4 +24,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[reflected light](/reference/sensors/color-sensor/reflected-light)

View File

@ -0,0 +1,26 @@
# calibrate Light
Calibrate the thresholds for dark and bright in current lighting conditions.
```sig
sensors.color1.calibrateLight(LightIntensityMode.Ambient, 0)
```
Sometimes when external lighting conditions change, the light sensor measures light intensty differently than when its thresholds were set before. You can calibrate the light sensor to adjust the thresholds slightly for current conditions. This is so that both the ``dark`` and ``bright`` threshold conditions happen with a similar amount of light to what you set the thresholds before.
## Parameters
* **mode**: the type of light threshold to calibrate. This is either ``ambient`` or ``reflected`` light.
* **deviation**: a [number](/types/number) that is the amount of light level change to adjust in a measurement.
## Example
Calibrate the ``dark`` and ``light`` thresholds for the ``color 2`` sensor using reflected light.
```blocks
sensors.color2.calibrateLight(LightIntensityMode.Reflected)
```
## See also
[set threshold](/reference/sensors/color-sensor/set-threshold)

View File

@ -1,5 +1,29 @@
# color
Get the current color detected by the sensor.
```sig
sensors.color1.color()
```
The [color](/reference/sensors/color) value returned is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Returns
* a color value for the current color detected by the color sensor. The colors detected are:
>* ``none``: no color is detected.
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## Example
Turn the status light to ``green`` if the color detected by the ``color 1`` sensor is green.
```blocks
forever(function () {
if (sensors.color1.color() == ColorSensorColor.Green) {
@ -8,4 +32,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[color](/reference/sensors/color-sensor/color)

View File

@ -0,0 +1,35 @@
# light
Get the amount of ambient or reflected light measured by the sensor.
```sig
sensors.color1.light(LightIntensityMode.Ambient)
```
The light sensor adjusts itself to more accurately measure light depending on the source of the light. You decide if you want to measure _ambient_ light (light all around or direct light) or if you want to know how much light is reflected from a surface. The amount of light measured is in the range of `0` (darkest) to `100` (brightest).
## Parameters
* **mode**: the type of measurement for light. This is either ``ambient`` or ``reflected`` light.
## Returns
* a number that is the amount of light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the ambient light is greater than `20`.
```blocks
forever(function () {
if (sensors.color1.light(LightIntensityMode.Ambient) > 20) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[calibrate light](/reference/sensors/color-sensor/calibrate-light)

View File

@ -1,16 +1,27 @@
# On Color Detected
# on Color Detected
Run some code when the color you want to watch for is detected.
```sig
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () { })
```
# Parameters
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Examples
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
* **handler**: the code you want to run when the color is detected.
## Example
Show an expression on the screen when the color sensor ``color 1`` sees ``blue``.
```blocks
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
brick.showImage(images.expressionsSick)
})
```
## See also
[pause for color](/reference/sensors/color-sensor/pause-for-color), [color](/reference/sensors/color)

View File

@ -0,0 +1,33 @@
# on Light Changed
Run some code when the amount of light dectected changes.
```sig
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
})
```
You can check for a change in either _ambient_ or _reflected_ light and run some code when it happens. This event happens when the sensor detects light going to ``dark`` or to ``bright``. You choose what condition you will run your code for.
## Parameters
* **mode**: lighting mode to use for detection. This is for either ``ambient`` or ``reflected`` light.
* **condition**: the condition that the light changed to: ``dark`` or ``bright``.
* **handler**: the code you want to run when the light changes.
## Example
Show a message on the screen when the ambient light goes dark.
```blocks
sensors.color1.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function() {
brick.clearScreen();
brick.showString("It just got dark", 1)
brick.showString("Can you see me?", 2)
})
```
## See also
[light](/reference/sensors/color-sensor/light), [on color detected](/reference/sensors/color-sensor/on-color-detected)

View File

@ -0,0 +1,28 @@
# pause For Color
Wait for the sensor to see a certain color.
```sig
sensors.color1.pauseForColor(ColorSensorColor.Blue)
```
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
## Example
Wait for the sensor to see ``blue``. Then, show an expression on the screen.
```blocks
brick.showString("Waiting for blue", 1)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on color detected](/reference/sensors/color-sensor/on-color-detected), [color](/reference/sensors/color)

View File

@ -0,0 +1,29 @@
# pause For Light
Wait for the light condition to change.
```sig
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
```
You can wait for a change in either _ambient_ or _reflected_ light. This event happens when the sensor detects light going to ``dark`` or to ``bright``. You choose what condition you will wait for.
## Parameters
* **mode**: lighting mode to use for detection. This is for either ``ambient`` or ``reflected`` light.
* **condition**: the condition that the light changed to: ``dark`` or ``bright``.
## Example
Wait for the ambient light to go dark, then show an expression on the screen.
```blocks
brick.showString("Waiting for dark", 1)
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on light changed](/reference/sensors/color-sensor/on-light-changed)

View File

@ -1,4 +1,20 @@
# Reflected Light
# reflected Light
Get the amount of reflected light dectected.
```sig
sensors.color1.reflectedLight()
```
The amount of reflected light measured is in the range of `0` (darkest) to `100` (brightest).
## Returns
* a [number](/types/number) that is the amount of ambiernt light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the reflected light is greater than `20`.
```blocks
forever(function () {
@ -8,4 +24,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[ambient light](/reference/sensors/color-sensor/ambient-light)

View File

@ -0,0 +1,41 @@
# set Threshold
Set the threshold value for dark or bright light.
```sig
sensors.color1.setThreshold(LightCondition.Dark, 0)
```
Light intensity is measured from `0` (very dark) to `100` (very bright). You can decide what dark and bright mean for your purposes and set a _threshold_ for them. A threshold is a boundary or a limit. If you want a light intensity of `20` mean that it's dark, then you set the sensor threshold for ``dark`` to `20`. Also, if you think that `75` is bright, then you can set the threshold for ``bright`` to that.
After setting a threshold, any event for that light condition won't happen until the amount of light reaches your threshold value:
```block
sensors.color1.setThreshold(LightCondition.Dark, 20)
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
brick.showMood(moods.sleeping)
})
```
## Parameters
* **condition**: the light intensity threshold to set, ``dark`` or ``bright``.
* **value**: the value of light intensity for the threshold: `0` for very dark to `100` for very bright.
## Example
Make a daylight alarm. When the ambient light reaches `70` flash the status light and play a sound.
```blocks
sensors.color3.setThreshold(LightCondition.Bright, 70)
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
brick.setStatusLight(StatusLight.GreenFlash)
for (let i = 0; i < 5; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalBackingAlert)
}
})
```
## See also
[threshold](/reference/sensors/color-sensor/threshold)

View File

@ -0,0 +1,27 @@
# threshold
Get the threshold value for dark or bright light.
```sig
sensors.color1.threshold(LightCondition.Dark)
```
Light intensity is measured from `0` (very dark) to `100` (very bright). A _threshold_ sets what dark and bright mean for your purposes. A threshold is a boundary or a limit. If a light intensity of `20` means that it's dark, then the sensor threshold for ``dark`` is `20`. Also, if `75` means bright, then the threshold value for ``bright`` is `75`.
## Returns
* a [number](/types/number) that is the amount of light set for the threshold. No light (darkness) is `0` and the brightest light is `100`.
## Example
Find out what light level is set as the ``dark`` threshold when a dark light event happens.
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
brick.showValue("DarknessThresholdValue", sensors.color3.threshold(LightCondition.Dark), 1)
})
```
## See also
[set threshold](/reference/sensors/color-sensor/set-threshold)

View File

@ -0,0 +1,55 @@
# color
Get a color that the sensor can detect that is close to the color you asked for.
```sig
sensors.color(ColorSensorColor.Blue)
```
Since the color sensor can accurately detect some basic colors, you can't just tell it to look for any color. The sensor may recoginze some color component of the color you ask for. So, you can get a simple color that matches some of your color and tell the sensor to look for that.
## Parameters
* **color**: a color to match with a detectable color. The colors to choose from are:
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## Returns
* a color value that the color sensor can detect. The detectable colors are:
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## ~hint
Currently, the colors you can ask for (input colors) and the colors returned are the same.
## ~
## Example
Turn the status light to ``green`` if the color detected by the ``color 1`` sensor is green.
```blocks
forever(function () {
if (sensors.color1.color() == sensors.color(ColorSensorColor.Green)) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[color](/reference/sensors/color-sensor/color)

View File

@ -421,28 +421,28 @@ namespace motors {
}
}
//% whenUsed fixedInstance block="large A"
//% whenUsed fixedInstance block="large motor A"
export const largeA = new Motor(Output.A, true);
//% whenUsed fixedInstance block="large B"
//% whenUsed fixedInstance block="large motor B"
export const largeB = new Motor(Output.B, true);
//% whenUsed fixedInstance block="large C"
//% whenUsed fixedInstance block="large motor C"
export const largeC = new Motor(Output.C, true);
//% whenUsed fixedInstance block="large D"
//% whenUsed fixedInstance block="large motor D"
export const largeD = new Motor(Output.D, true);
//% whenUsed fixedInstance block="medium A"
//% whenUsed fixedInstance block="medium motor A"
export const mediumA = new Motor(Output.A, false);
//% whenUsed fixedInstance block="medium B"
//% whenUsed fixedInstance block="medium motor B"
export const mediumB = new Motor(Output.B, false);
//% whenUsed fixedInstance block="medium C"
//% whenUsed fixedInstance block="medium motor C"
export const mediumC = new Motor(Output.C, false);
//% whenUsed fixedInstance block="medium D"
//% whenUsed fixedInstance block="medium motor D"
export const mediumD = new Motor(Output.D, false);
//% fixedInstances
@ -586,16 +586,16 @@ namespace motors {
}
}
//% whenUsed fixedInstance block="large B+C"
//% whenUsed fixedInstance block="large motors B+C"
export const largeBC = new SynchedMotorPair(Output.BC);
//% whenUsed fixedInstance block="large A+D"
//% whenUsed fixedInstance block="large motors A+D"
export const largeAD = new SynchedMotorPair(Output.AD);
//% whenUsed fixedInstance block="large A+B"
//% whenUsed fixedInstance block="large motors A+B"
export const largeAB = new SynchedMotorPair(Output.AB);
//% whenUsed fixedInstance block="large C+D"
//% whenUsed fixedInstance block="large motors C+D"
export const largeCD = new SynchedMotorPair(Output.CD);
function reset(out: Output) {

View File

@ -0,0 +1,17 @@
# Infrared beacon
```cards
sensors.remoteButtonCenter.onEvent(ButtonEvent.Pressed, function () {})
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
sensors.remoteButtonCenter.isPressed()
sensors.remoteButtonCenter.wasPressed()
sensors.infraredSensor1.setRemoteChannel(null)
```
## See also
[on event](/reference/sensors/beacon/on-event),
[pause until](/reference/sensors/beacon/pause-until),
[is pressed](/reference/sensors/beacon/is-pressed)
[was pressed](/reference/sensors/beacon/was-pressed)
[set remote channel](/reference/sensors/beacon/set-remote-channel)

View File

@ -0,0 +1,44 @@
# is Pressed
Check to see if a remote beacon button is currently pressed or not.
```sig
sensors.remoteButtonBottomLeft.isPressed()
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Returns
* a [boolean](/types/boolean) value that is `true` if the beacon button is currently pressed. It's `false` if the button is not pressed.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
If the beacon button ``center`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
sensors.infraredSensor1.setRemoteChannel(InfraredRemoteChannel.Ch0)
forever(function () {
if (sensors.remoteButtonCenter.isPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[was pressed](/reference/sensors/beacon/was-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,46 @@
# on Event
Run some code when a remote beacon button is pressed, bumped, or released.
```sig
sensors.remoteButtonBottomLeft.onEvent(ButtonEvent.Bumped, function () {});
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Parameters
* **ev**: the beacon button action to run some code for. The button actions (events) are:
> * ``pressed``: the button was pressed, or pressed and released
> * ``bumped``: the button was just bumped
> * ``released``: the button was just released
* **body**: the code you want to run when something happens to the beacon button.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
Check for an event on beacon button sensor ``center``. Put an expression on the screen when the button is released.
```blocks
sensors.infraredSensor1.setRemoteChannel(InfraredRemoteChannel.Ch0)
sensors.remoteButtonCenter.onEvent(ButtonEvent.Released, function () {
brick.showImage(images.expressionsSick)
})
```
### See also
[is pressed](/reference/sensors/beacon/is-pressed),
[was pressed](/reference/sensors/beacon/was-pressed),
[pause until](/reference/sensors/beacon/pause-until)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,53 @@
# pause Until
Make your program wait until a button event from a remote beacon happens.
```sig
sensors.remoteButtonBottomLeft.pauseUntil(ButtonEvent.Bumped);
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Parameters
* **ev**: the beacon button action to wait for. The button actions (events) are:
> * ``pressed``: the button was pressed, or pressed and released
> * ``bumped``: the button was just bumped
> * ``released``: the button was just released
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
Wait for a bump to beacon button `center` before continuing with displaying a message on the screen.
```blocks
let waitTime = 0;
brick.clearScreen();
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.infraredSensor1.setRemoteChannel(InfraredRemoteChannel.Ch0)
sensors.remoteButtonCenter.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/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,35 @@
# set Remote Channel
Set the remote infrared signal channel for an infrared sensor.
```sig
sensors.infraredSensor1.setRemoteChannel(InfraredRemoteChannel.Ch0)
```
An infrared sensor connected to the @boardname@ can receive messages (signals for button events) from a remote infrared beacon. In order for the sensor to know which beacon to receive messages from, a _channel_ is used. The beacon has a switch on it to select a particular channel to transmit on. The sensor needs to know which channel to receive ("listen" for) messages from the beacon.
A sensor is not automatically set to listen for infrared messages on a channel. To avoid confusion on which sensor receives signals from a beacon, each sensor (if you have more than one), sets a remote channel for itself. The channel number matches the channel selected on the beacon.
## Parameters
* **channel**: the channel for the infrared sensor to "listen" on. You can choose to use one of 4 channels: ``0``, ``1``, ``2``, and ``3``.
## Example
Select channel **2** on an infrared beacon. Set the remote channel for infrared sensor ``infrared 3`` to channel ``2``. Wait for the ``center`` button press on the beacon using channel ``2``.
```blocks
sensors.infraredSensor3.setRemoteChannel(InfraredRemoteChannel.Ch2);
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
brick.clearScreen();
brick.showString("Center button on", 1);
brick.showString("channel 2 beacon", 2);
brick.showString("was pressed.", 3);
```
## See also
[was pressed](/reference/sensors/beacon/was-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,47 @@
# was Pressed
See if a button on a remote infrared beacon was pressed since the last time it was checked.
```sig
sensors.remoteButtonBottomLeft.wasPressed()
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
If a button was pressed, then that event is remembered. Once you check if a beacon button **was pressed**, that status is set back to `false`. If you check again before the beacon button is pressed another time, the **was pressed** status is `false`. Only when the button is pressed will the **was pressed** status go to `true`.
## Returns
* a [boolean](/types/boolean) value that is `true` if the beacon button was pressed before. It's `false` if the button was not pressed.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
If the beacon button ``top left`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
sensors.infraredSensor1.setRemoteChannel(InfraredRemoteChannel.Ch0)
forever(function () {
if (sensors.remoteButtonTopLeft.wasPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
pause(500)
})
```
## See also
[is pressed](/reference/sensors/beacon/is-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,32 @@
# proximity Threshold
Get the proximity threshold for when objects are near and detected.
```sig
sensors.infraredSensor1.proximityThreshold(InfraredSensorEvent.ObjectNear)
```
Infrared sensors determine proximity of an object by measuring the intensity of the infrared light reflected from it. The proximity range of measurment is from `0` to `100`. Proximity _thresholds_ use a value in this range to decide when a proximity event should happen for a detected object.
## Parameters
* **condition**: the proximity threshold to return a value for. These are: ``near`` and ``detected``.
## Returns
* a [number](/types/number) that is the proximity value for the threshold. This is a number between `0` and `100`.
## Example
When an object with near proximity is detected, show what the threshold is.
```blocks
sensors.infraredSensor1.onEvent(InfraredSensorEvent.ObjectNear, function () {
brick.showValue("NearObjectThreshold", sensors.infraredSensor1.proximityThreshold(InfraredSensorEvent.ObjectNear)
, 1)
})
```
## See also
[set proximity threshold](/reference/sensors/infrared/set-proximity-threshold)

View File

@ -0,0 +1,35 @@
# set Proximity Threshold
Set the proximity threshold for when objects are near or detected.
```sig
sensors.infraredSensor1.setPromixityThreshold(InfraredSensorEvent.ObjectNear, 0)
```
Infrared sensors determine proximity of an object by measuring the intensity of the infrared light reflected from it. The proximity range of measurment is from `0` to `100`. You can decide what value in that range you want mean that something is near or that something was detected.
If you want a proximity value of `32` to mean that a detected object is near, then the ``near`` threshold is set to that value. If you want any object within a proximity of `95` to cause a detection event, then the ``detected`` threshold is set to `95`.
## Parameters
* **condition**: the threshold condition to use this proximity. These are: ``near`` and ``detected``.
* **value**: a proximity [number](/types/number) to set the threshold for.
## Example
Set a threshold for detecting something moving within a proximity `30`. Wait for an object to show up. When it does, flash the status light and make noise as an alarm.
```blocks
sensors.infraredSensor1.setPromixityThreshold(InfraredSensorEvent.ObjectDetected, 30)
sensors.infraredSensor1.pauseUntil(InfraredSensorEvent.ObjectDetected)
brick.clearScreen()
brick.showString("Perimeter Breach!!!", 3)
brick.setStatusLight(StatusLight.RedFlash)
for (let i = 0; i < 10; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalHorn2)
}
```
## See also
[proximity threshold](/reference/sensors/infrared/proximity-threshold)

View File

@ -83,7 +83,7 @@ namespace sensors {
* Check if a remote button is currently pressed or not.
* @param button the remote button to query the request
*/
//% help=input/remote-infrared-beacon/is-pressed
//% help=sensors/beacon/is-pressed
//% block="%button|is pressed"
//% blockId=remoteButtonIsPressed
//% parts="remote"
@ -98,7 +98,7 @@ namespace sensors {
* See if the remote button was pressed again since the last time you checked.
* @param button the remote button to query the request
*/
//% help=input/remote-infrared-beacon/was-pressed
//% help=sensors/beacon/was-pressed
//% block="%button|was pressed"
//% blockId=remotebuttonWasPressed
//% parts="remote"
@ -110,12 +110,12 @@ namespace sensors {
}
/**
* Do something when a button or sensor is clicked, up or down
* Do something when a remote button is pressed, bumped, or released
* @param button the button that needs to be clicked or used
* @param event the kind of button gesture that needs to be detected
* @param body code to run when the event is raised
*/
//% help=input/remote-infrared-beacon/on-event
//% help=sensors/beacon/on-event
//% blockId=remotebuttonEvent block="on %button|%event"
//% parts="remote"
//% blockNamespace=sensors
@ -126,10 +126,10 @@ namespace sensors {
}
/**
* Pauses until the given event is raised
* Pause until a remote button event happens
* @param ev the event to wait for
*/
//% help=input/remote-infrared-beacon/pause-until
//% help=sensors/beacon/pause-until
//% blockId=remoteButtonPauseUntil block="pause until %button|%event"
//% parts="remote"
//% blockNamespace=sensors
@ -181,7 +181,7 @@ namespace sensors {
}
/**
* Registers code to run when an object is getting near.
* Register code to run when an object is getting near.
* @param handler the code to run when detected
*/
//% help=sensors/infrared/on-event
@ -197,7 +197,7 @@ namespace sensors {
}
/**
* Waits for the event to occur
* Wait until the infrared sensor detects something
*/
//% help=sensors/infrared/pause-until
//% block="pause until %sensor| %event"
@ -228,13 +228,14 @@ namespace sensors {
}
/**
* Sets the remote channel to listen from
* Set the remote channel to listen to
* @param channel the channel to listen
*/
//% blockNamespace=sensors
//% blockId=irSetRemoteChannel block="set %sensor|remote channel to %channel"
//% weight=99
//% group="Remote Infrared Beacon"
//% help=sensors/beacon/set-remote-channel
setRemoteChannel(channel: InfraredRemoteChannel) {
this.setMode(InfraredSensorMode.RemoteControl)
channel = Math.clamp(0, 3, channel | 0)
@ -257,7 +258,7 @@ namespace sensors {
}
/**
* Gets the threshold value
* Get a threshold value
* @param condition the proximity condition
*/
//% blockId=irGetThreshold block="%sensor|%condition"

View File

@ -10,7 +10,7 @@ sensors.touch1.onEvent(ButtonEvent.Bumped, function () {
## Parameters
* **ev**: the touch sensor action to run some code for. The the touch actions (events) are:
* **ev**: the touch sensor action to run some code for. 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
@ -18,7 +18,7 @@ sensors.touch1.onEvent(ButtonEvent.Bumped, function () {
## Example
Check for an event on touch sensor ``touch 1``. Put an expression on the screen when the senosr is released.
Check for an event on touch sensor ``touch 1``. Put an expression on the screen when the sensor is released.
```blocks
sensors.touch1.onEvent(ButtonEvent.Released, function () {

View File

@ -8,7 +8,7 @@ sensors.touch1.pauseUntil(ButtonEvent.Bumped);
## Parameters
* **ev**: the touch sensor action to wait for. The the touch actions (events) are:
* **ev**: the touch sensor action to wait for. 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

View File

@ -10,7 +10,7 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
## 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.
* a [boolean](/types/boolean) value that is `true` if the sensor was pressed before. It's `false` if the sensor was not pressed.
## Example

View File

@ -0,0 +1,37 @@
# set Threshold
Set the distance threshold for when objects are near, far, or detected.
```sig
sensors.ultrasonic1.setThreshold(UltrasonicSensorEvent.ObjectDetected, 0)
```
Whether something is near or far away really depends on the situation. A object moving towards you is "near" at further distance than something that isn't moving due to the time necessary to move out of its way. So, in certain situations you may want change which distances mean near or far.
You can change the distances for near and far by setting their _thresholds_. A threshold is a boundary or a limit. If you wanted near to mean anything that's closer that 20 centimeters, then that is your threshold for ``near``. Also, if anything further than 35 centimeters is thought of as far, then the threshold for ``far`` is `35`.
Similarly, if you are just concerned about knowing that something has moved within a distance from you, then you set that distance as the threshold for ``detected``.
## Parameters
* **condition**: the threshold condition to set a distance for. These are: ``near``, ``far``, and ``detected``.
* **value**: a [number](/types/number) that the distance in centimeters to set the threshold for.
## Example
Set a threshold for detecting something moving within 30 centimeters. Wait for an object to show up. When it does, flash the status light and make noise as an alarm.
```blocks
sensors.ultrasonic1.setThreshold(UltrasonicSensorEvent.ObjectDetected, 30)
sensors.ultrasonic1.pauseUntil(UltrasonicSensorEvent.ObjectDetected)
brick.clearScreen()
brick.showString("Perimeter Breach!!!", 3)
brick.setStatusLight(StatusLight.RedFlash)
for (let i = 0; i < 10; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalHorn2)
}
```
## See also
[threshold](/reference/sensors/ultrasonic/threshold)

View File

@ -0,0 +1,35 @@
# threshold
Get the distance threshold for when objects are near, far, or detected.
```sig
sensors.ultrasonic1.threshold(UltrasonicSensorEvent.ObjectDetected)
```
Whether something is near or far away really depends on the situation. A object moving towards you is "near" at further distance than something that isn't moving due to the time necessary to move out of its way.
Distances for near and far by have set _thresholds_. A threshold is a boundary or a limit. If near means anything that's closer that 20 centimeters, then the threshold for ``near``. Also, if anything further than 35 centimeters is thought of as far, then the threshold for ``far`` is `35`.
Also, the threshold for nowing that something has moved within a distance from you is set for ``detected``.
## Parameters
* **condition**: the condition to get the threshold distance for. These are: ``near``, ``far``, and ``detected``.
## Returns
* a [number](/types/number) that is the threshold distance in centimeters.
## Example
When a near object is detected, show what the threshold is.
```blocks
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
brick.showValue("NearObjectThreshold", sensors.ultrasonic4.threshold(UltrasonicSensorEvent.ObjectNear), 1)
})
```
## See also
[set threshold](/reference/sensors/ultrasonic/set-threshold)

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.104",
"version": "0.0.106",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.104",
"version": "0.0.106",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -46,7 +46,7 @@
},
"dependencies": {
"pxt-common-packages": "0.19.5",
"pxt-core": "3.4.6"
"pxt-core": "3.4.8"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"