updated naming
This commit is contained in:
parent
4d2b7ced71
commit
97663d2b83
@ -1,8 +1,9 @@
|
||||
{
|
||||
"sensors.ColorSensor": "The color sensor is a digital sensor that can detect the color or intensity\nof light that enters the small window on the face of the sensor.",
|
||||
"sensors.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
|
||||
"sensors.ColorSensor.color": "Get the current color from the color sensor.",
|
||||
"sensors.ColorSensor.colorMode": "Gets the current color mode",
|
||||
"sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected",
|
||||
"sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected.",
|
||||
"sensors.ColorSensor.onColorDetected|param|color": "the color to detect, eg: ColorSensorColor.Blue",
|
||||
"sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
|
||||
"sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor."
|
||||
|
@ -7,14 +7,18 @@
|
||||
"ColorSensorColor.Red|block": "red",
|
||||
"ColorSensorColor.White|block": "white",
|
||||
"ColorSensorColor.Yellow|block": "yellow",
|
||||
"ColorSensorMode.AmbientLightIntensity|block": "ambient light intensity",
|
||||
"ColorSensorMode.Color|block": "color",
|
||||
"ColorSensorMode.ReflectedLightIntensity|block": "reflected light intensity",
|
||||
"sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light",
|
||||
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
|
||||
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected color %color",
|
||||
"sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light",
|
||||
"sensors.color1|block": "1",
|
||||
"sensors.color2|block": "2",
|
||||
"sensors.color3|block": "3",
|
||||
"sensors.color4|block": "4",
|
||||
"sensors.colorSensor1|block": "1",
|
||||
"sensors.colorSensor2|block": "2",
|
||||
"sensors.colorSensor3|block": "3",
|
||||
"sensors.colorSensor4|block": "4",
|
||||
"sensors|block": "sensors",
|
||||
"{id:category}Sensors": "Sensors",
|
||||
"{id:group}Color Sensor": "Color Sensor"
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
const enum ColorSensorMode {
|
||||
None = -1,
|
||||
Reflect = 0,
|
||||
Ambient = 1,
|
||||
//% block="reflected light intensity"
|
||||
ReflectedLightIntensity = 0,
|
||||
//% block="ambient light intensity"
|
||||
AmbientLightIntensity = 1,
|
||||
//% block="color"
|
||||
Color = 2,
|
||||
RefRaw = 3,
|
||||
RgbRaw = 4,
|
||||
@ -29,6 +32,10 @@ const enum ColorSensorColor {
|
||||
|
||||
namespace sensors {
|
||||
|
||||
/**
|
||||
* The color sensor is a digital sensor that can detect the color or intensity
|
||||
* of light that enters the small window on the face of the sensor.
|
||||
*/
|
||||
//% fixedInstances
|
||||
export class ColorSensor extends internal.UartSensor {
|
||||
constructor(port: number) {
|
||||
@ -62,11 +69,11 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when the given color is detected
|
||||
* Registers code to run when the given color is detected.
|
||||
* @param color the color to detect, eg: ColorSensorColor.Blue
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=input/color/on-color-detected
|
||||
//% help=sensors/color-sensor/on-color-detected
|
||||
//% block="on `icons.colorSensor` %sensor|detected color %color"
|
||||
//% blockId=colorOnColorDetected
|
||||
//% parts="colorsensor"
|
||||
@ -80,43 +87,11 @@ namespace sensors {
|
||||
control.raiseEvent(this._id, <number>color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current ambient light value from the color sensor.
|
||||
* @param color the color sensor to query the request
|
||||
*/
|
||||
//% help=input/color/ambient-light
|
||||
//% block="`icons.colorSensor` %color| ambient light"
|
||||
//% blockId=colorGetAmbient
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
ambientLight() {
|
||||
this.setColorMode(ColorSensorMode.Ambient)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current reflected light value from the color sensor.
|
||||
* @param color the color sensor to query the request
|
||||
*/
|
||||
//% help=input/color/refelected-light
|
||||
//% block="`icons.colorSensor` %color| reflected light"
|
||||
//% blockId=colorGetReflected
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=64 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
reflectedLight(): number {
|
||||
this.setColorMode(ColorSensorMode.Reflect)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current color from the color sensor.
|
||||
* @param color the color sensor to query the request
|
||||
*/
|
||||
//% help=input/color/color
|
||||
//% help=sensors/color-sensor/color
|
||||
//% block="`icons.colorSensor` %color| color"
|
||||
//% blockId=colorGetColor
|
||||
//% parts="colorsensor"
|
||||
@ -127,17 +102,49 @@ namespace sensors {
|
||||
this.setColorMode(ColorSensorMode.Color)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current ambient light value from the color sensor.
|
||||
* @param color the color sensor to query the request
|
||||
*/
|
||||
//% help=sensors/color-sensor/ambient-light
|
||||
//% block="`icons.colorSensor` %color| ambient light"
|
||||
//% blockId=colorGetAmbient
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=65 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
ambientLight() {
|
||||
this.setColorMode(ColorSensorMode.AmbientLightIntensity)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current reflected light value from the color sensor.
|
||||
* @param color the color sensor to query the request
|
||||
*/
|
||||
//% help=sensors/color-sensor/reflected-light
|
||||
//% block="`icons.colorSensor` %color| reflected light"
|
||||
//% blockId=colorGetReflected
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=64 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
reflectedLight(): number {
|
||||
this.setColorMode(ColorSensorMode.ReflectedLightIntensity)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
}
|
||||
|
||||
//% whenUsed block="1" weight=95 fixedInstance
|
||||
export const color1: ColorSensor = new ColorSensor(1)
|
||||
export const colorSensor1: ColorSensor = new ColorSensor(1)
|
||||
|
||||
//% whenUsed block="3" weight=90 fixedInstance
|
||||
export const color3: ColorSensor = new ColorSensor(3)
|
||||
export const colorSensor3: ColorSensor = new ColorSensor(3)
|
||||
|
||||
//% whenUsed block="2" weight=90 fixedInstance
|
||||
export const color2: ColorSensor = new ColorSensor(2)
|
||||
export const colorSensor2: ColorSensor = new ColorSensor(2)
|
||||
|
||||
//% whenUsed block="4" weight=90 fixedInstance
|
||||
export const color4: ColorSensor = new ColorSensor(4)
|
||||
export const colorSensor4: ColorSensor = new ColorSensor(4)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user