First burst of 'color' pages (#335)
* Add 'color sensor' api topics * Last set of edits/adds
This commit is contained in:
parent
ceb9b7fabf
commit
84c8e31ff5
@ -98,3 +98,10 @@
|
|||||||
* [on event](/reference/sensors/infrared/on-event),
|
* [on event](/reference/sensors/infrared/on-event),
|
||||||
* [distance](reference/sensors/infrared/proximity),
|
* [distance](reference/sensors/infrared/proximity),
|
||||||
* [pause until](reference/sensors/infrared/pause-until)
|
* [pause until](reference/sensors/infrared/pause-until)
|
||||||
|
* [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)
|
@ -1,5 +1,17 @@
|
|||||||
# Sensors
|
# 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
|
## Touch
|
||||||
|
|
||||||
```cards
|
```cards
|
||||||
|
@ -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
|
* @param color the color to detect
|
||||||
*/
|
*/
|
||||||
//% help=sensors/color-sensor/pause-for-light
|
//% 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
|
* @param sensor the color sensor port
|
||||||
*/
|
*/
|
||||||
//% help=sensors/color-sensor/light
|
//% 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 condition the dark or bright light condition
|
||||||
* @param value the value threshold
|
* @param value the value threshold
|
||||||
*/
|
*/
|
||||||
@ -253,7 +253,7 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the threshold value
|
* Get a threshold value
|
||||||
* @param condition the light condition
|
* @param condition the light condition
|
||||||
*/
|
*/
|
||||||
//% blockId=colorGetThreshold block="%sensor|%condition"
|
//% blockId=colorGetThreshold block="%sensor|%condition"
|
||||||
@ -318,6 +318,7 @@ namespace sensors {
|
|||||||
//% blockId=colorSensorColor block="color %color"
|
//% blockId=colorSensorColor block="color %color"
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
//% weight=97
|
//% weight=97
|
||||||
|
//% help=sensors/color
|
||||||
//% color.fieldEditor="gridpicker"
|
//% color.fieldEditor="gridpicker"
|
||||||
//% color.fieldOptions.columns=4
|
//% color.fieldOptions.columns=4
|
||||||
//% color.fieldOptions.tooltips=true
|
//% color.fieldOptions.tooltips=true
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
# Color Sensor
|
# Color sensor
|
||||||
|
|
||||||
```cards
|
```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.color();
|
||||||
sensors.color1.ambientLight();
|
sensors.color1.light(LightIntensityMode.Ambient)
|
||||||
sensors.color1.reflectedLight();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## See Also
|
## See slso
|
||||||
|
|
||||||
[on color detected](/reference/sensors/color-sensor/on-color-detected),
|
[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),
|
[color](/reference/sensors/color-sensor/color),
|
||||||
[ambient light](/reference/sensors/color-sensor/ambient-light),
|
[light](/reference/sensors/color-sensor/ambient-light)
|
||||||
[reflected light](/reference/sensors/color-sensor/reflected-light),
|
|
||||||
|
@ -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
|
```blocks
|
||||||
forever(function () {
|
forever(function () {
|
||||||
@ -9,3 +25,7 @@ forever(function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[reflected light](/reference/sensors/color-sensor/reflected-light)
|
@ -1,5 +1,29 @@
|
|||||||
# color
|
# 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``
|
||||||
|
>* ``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
|
```blocks
|
||||||
forever(function () {
|
forever(function () {
|
||||||
if (sensors.color1.color() == ColorSensorColor.Green) {
|
if (sensors.color1.color() == ColorSensorColor.Green) {
|
||||||
@ -9,3 +33,7 @@ forever(function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[color](/reference/sensors/color-sensor/color)
|
@ -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
|
||||||
|
|
||||||
|
[reflected light](/reference/sensors/color-sensor/reflected-light)
|
@ -1,16 +1,27 @@
|
|||||||
# On Color Detected
|
# on Color Detected
|
||||||
|
|
||||||
|
Run some code when the color you want to watch for is detected.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () { })
|
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
|
```blocks
|
||||||
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||||
brick.showImage(images.expressionsSick)
|
brick.showImage(images.expressionsSick)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[pause for color](/reference/sensors/color-sensor/pause-for-color), [color](/reference/sensors/color)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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
|
```blocks
|
||||||
forever(function () {
|
forever(function () {
|
||||||
@ -9,3 +25,7 @@ forever(function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
[ambient light](/reference/sensors/color-sensor/ambient-light)
|
57
libs/color-sensor/docs/reference/sensors/color.md
Normal file
57
libs/color-sensor/docs/reference/sensors/color.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# 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:
|
||||||
|
|
||||||
|
>* ``none``
|
||||||
|
>* ``blue``
|
||||||
|
>* ``green``
|
||||||
|
>* ``yellow``
|
||||||
|
>* ``red``
|
||||||
|
>* ``white``
|
||||||
|
>* ``brown``
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
* a color value that the color sensor can detect. The detectable colors are:
|
||||||
|
|
||||||
|
>* ``none``
|
||||||
|
>* ``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)
|
Loading…
Reference in New Issue
Block a user