parent
a71dee2923
commit
3d73f193a8
@ -17,5 +17,6 @@
|
|||||||
"sensors.ColorSensor.setThreshold|param|condition": "the dark or bright light condition",
|
"sensors.ColorSensor.setThreshold|param|condition": "the dark or bright light condition",
|
||||||
"sensors.ColorSensor.setThreshold|param|value": "the value threshold",
|
"sensors.ColorSensor.setThreshold|param|value": "the value threshold",
|
||||||
"sensors.ColorSensor.threshold": "Gets the threshold value",
|
"sensors.ColorSensor.threshold": "Gets the threshold value",
|
||||||
"sensors.ColorSensor.threshold|param|condition": "the light condition"
|
"sensors.ColorSensor.threshold|param|condition": "the light condition",
|
||||||
|
"sensors.color": "Returns a color that the sensor can detect"
|
||||||
}
|
}
|
@ -26,6 +26,7 @@
|
|||||||
"sensors.color2|block": "color 2",
|
"sensors.color2|block": "color 2",
|
||||||
"sensors.color3|block": "color 3",
|
"sensors.color3|block": "color 3",
|
||||||
"sensors.color4|block": "color 4",
|
"sensors.color4|block": "color 4",
|
||||||
|
"sensors.color|block": "color %color",
|
||||||
"sensors|block": "sensors",
|
"sensors|block": "sensors",
|
||||||
"{id:category}Sensors": "Sensors",
|
"{id:category}Sensors": "Sensors",
|
||||||
"{id:group}Color Sensor": "Color Sensor",
|
"{id:group}Color Sensor": "Color Sensor",
|
||||||
|
@ -19,21 +19,21 @@ enum LightIntensityMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const enum ColorSensorColor {
|
const enum ColorSensorColor {
|
||||||
//% block="none"
|
//% block="none" blockIdentity=sensors.color
|
||||||
None,
|
None,
|
||||||
//% block="black"
|
//% block="black" blockIdentity=sensors.color
|
||||||
Black,
|
Black,
|
||||||
//% block="blue"
|
//% block="blue" blockIdentity=sensors.color
|
||||||
Blue,
|
Blue,
|
||||||
//% block="green"
|
//% block="green" blockIdentity=sensors.color
|
||||||
Green,
|
Green,
|
||||||
//% block="yellow"
|
//% block="yellow" blockIdentity=sensors.color
|
||||||
Yellow,
|
Yellow,
|
||||||
//% block="red"
|
//% block="red" blockIdentity=sensors.color
|
||||||
Red,
|
Red,
|
||||||
//% block="white"
|
//% block="white" blockIdentity=sensors.color
|
||||||
White,
|
White,
|
||||||
//% block="brown"
|
//% block="brown" blockIdentity=sensors.color
|
||||||
Brown,
|
Brown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +157,7 @@ namespace sensors {
|
|||||||
//% sensor.fieldEditor="ports"
|
//% sensor.fieldEditor="ports"
|
||||||
//% weight=98
|
//% weight=98
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
|
//% blockGap=8
|
||||||
color(): ColorSensorColor {
|
color(): ColorSensorColor {
|
||||||
this.setMode(ColorSensorMode.Color)
|
this.setMode(ColorSensorMode.Color)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
@ -270,13 +271,13 @@ namespace sensors {
|
|||||||
let min = 200;
|
let min = 200;
|
||||||
let max = -200;
|
let max = -200;
|
||||||
let k = 0;
|
let k = 0;
|
||||||
while(k++ < 1000 && vcount < 50) {
|
while (k++ < 1000 && vcount < 50) {
|
||||||
let v = this.light(mode);
|
let v = this.light(mode);
|
||||||
min = Math.min(min, v);
|
min = Math.min(min, v);
|
||||||
max = Math.max(max, v);
|
max = Math.max(max, v);
|
||||||
// detect if nothing has changed and stop calibration
|
// detect if nothing has changed and stop calibration
|
||||||
if (Math.abs(v - vold) <= 2)
|
if (Math.abs(v - vold) <= 2)
|
||||||
vcount ++;
|
vcount++;
|
||||||
else {
|
else {
|
||||||
vold = v;
|
vold = v;
|
||||||
vcount = 1;
|
vcount = 1;
|
||||||
@ -297,6 +298,18 @@ namespace sensors {
|
|||||||
|
|
||||||
this.calibrating = false;
|
this.calibrating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a color that the sensor can detect
|
||||||
|
*/
|
||||||
|
//% shim=TD_ID
|
||||||
|
//% blockId=colorSensorColor block="color %color"
|
||||||
|
//% group="Color Sensor"
|
||||||
|
//% weight=97
|
||||||
|
export function color(color: ColorSensorColor): ColorSensorColor {
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
//% whenUsed block="color 3" weight=95 fixedInstance jres=icons.port3
|
//% whenUsed block="color 3" weight=95 fixedInstance jres=icons.port3
|
||||||
|
Loading…
Reference in New Issue
Block a user