Merge pull request #16 from Microsoft/fonts
Mounting events on various sensors
This commit is contained in:
commit
90560050b8
@ -26,6 +26,9 @@
|
|||||||
"input.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
|
"input.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
|
||||||
"input.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
|
"input.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
|
||||||
"input.ColorSensor.color": "Get the current color from the color sensor.",
|
"input.ColorSensor.color": "Get the current color from the color sensor.",
|
||||||
|
"input.ColorSensor.onColorDetected": "Registers code to run when the given color is detected",
|
||||||
|
"input.ColorSensor.onColorDetected|param|color": "the color to dtect",
|
||||||
|
"input.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
|
||||||
"input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
|
"input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
|
||||||
"input.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
"input.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
||||||
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
"ButtonEvent.Click|block": "click",
|
"ButtonEvent.Click|block": "click",
|
||||||
"ButtonEvent.Down|block": "down",
|
"ButtonEvent.Down|block": "down",
|
||||||
"ButtonEvent.Up|block": "up",
|
"ButtonEvent.Up|block": "up",
|
||||||
|
"ColorSensorColor.Black|block": "black",
|
||||||
|
"ColorSensorColor.Blue|block": "blue",
|
||||||
|
"ColorSensorColor.Brown|block": "brown",
|
||||||
|
"ColorSensorColor.Green|block": "green",
|
||||||
|
"ColorSensorColor.None|block": "none",
|
||||||
|
"ColorSensorColor.Red|block": "red",
|
||||||
|
"ColorSensorColor.White|block": "white",
|
||||||
|
"ColorSensorColor.Yellow|block": "yellow",
|
||||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||||
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
||||||
"LightsPattern.Green|block": "Green",
|
"LightsPattern.Green|block": "Green",
|
||||||
@ -27,6 +35,7 @@
|
|||||||
"input.Button.wasPressed|block": "%button|was pressed",
|
"input.Button.wasPressed|block": "%button|was pressed",
|
||||||
"input.ColorSensor.ambientLight|block": "%color| ambient light",
|
"input.ColorSensor.ambientLight|block": "%color| ambient light",
|
||||||
"input.ColorSensor.color|block": "%color| color",
|
"input.ColorSensor.color|block": "%color| color",
|
||||||
|
"input.ColorSensor.onColorDetected|block": "on %sensor|detected %color",
|
||||||
"input.ColorSensor.reflectedLight|block": "%color| reflected light",
|
"input.ColorSensor.reflectedLight|block": "%color| reflected light",
|
||||||
"input.GyroSensor.angle|block": "%sensor|angle",
|
"input.GyroSensor.angle|block": "%sensor|angle",
|
||||||
"input.GyroSensor.rate|block": "%sensor|rotation rate",
|
"input.GyroSensor.rate|block": "%sensor|rotation rate",
|
||||||
|
@ -9,13 +9,21 @@ const enum ColorSensorMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const enum ColorSensorColor {
|
const enum ColorSensorColor {
|
||||||
|
//% block="none"
|
||||||
None,
|
None,
|
||||||
|
//% block="black"
|
||||||
Black,
|
Black,
|
||||||
|
//% block="blue"
|
||||||
Blue,
|
Blue,
|
||||||
|
//% block="green"
|
||||||
Green,
|
Green,
|
||||||
|
//% block="yellow"
|
||||||
Yellow,
|
Yellow,
|
||||||
|
//% block="red"
|
||||||
Red,
|
Red,
|
||||||
|
//% block="white"
|
||||||
White,
|
White,
|
||||||
|
//% block="brown"
|
||||||
Brown,
|
Brown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +43,35 @@ namespace input {
|
|||||||
this._setMode(m)
|
this._setMode(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_query() {
|
||||||
|
if (this.mode == ColorSensorMode.Color)
|
||||||
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_update(prev: number, curr: number) {
|
||||||
|
control.raiseEvent(this._id, curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers code to run when the given color is detected
|
||||||
|
* @param color the color to dtect
|
||||||
|
* @param handler the code to run when detected
|
||||||
|
*/
|
||||||
|
//% help=input/color/on-color-detected
|
||||||
|
//% block="on %sensor|detected %color"
|
||||||
|
//% blockId=colorOnColorDetected
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=input
|
||||||
|
//% weight=100 blockGap=8
|
||||||
|
//% group="Color Sensor"
|
||||||
|
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
||||||
|
control.onEvent(this._id, <number>color, handler);
|
||||||
|
this.setMode(ColorSensorMode.Color)
|
||||||
|
if (this.color() == color)
|
||||||
|
control.runInBackground(handler)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current ambient light value from the color sensor.
|
* Get current ambient light value from the color sensor.
|
||||||
* @param color the color sensor to query the request
|
* @param color the color sensor to query the request
|
||||||
|
Loading…
Reference in New Issue
Block a user