simplified events
This commit is contained in:
parent
282134f5dc
commit
21b34cb459
@ -32,8 +32,7 @@
|
||||
"input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
|
||||
"input.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
||||
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
||||
"input.InfraredSensor.onObjectNear": "Registers code to run when an object is getting near",
|
||||
"input.InfraredSensor.onObjectNear|param|distance": "the proximity, eg: 10",
|
||||
"input.InfraredSensor.onObjectNear": "Registers code to run when an object is getting near.",
|
||||
"input.InfraredSensor.onObjectNear|param|handler": "the code to run when detected",
|
||||
"input.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)",
|
||||
"input.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
|
||||
@ -42,7 +41,6 @@
|
||||
"input.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
||||
"input.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
|
||||
"input.UltraSonicSensor.onObjectNear": "Registers code to run when the given color is close",
|
||||
"input.UltraSonicSensor.onObjectNear|param|distance": "the distance in centimeters when an object is close, eg: 10",
|
||||
"input.UltraSonicSensor.onObjectNear|param|handler": "the code to run when detected",
|
||||
"input.buttonDown": "Down button on the EV3 Brick.",
|
||||
"input.buttonEnter": "Enter button on the EV3 Brick.",
|
||||
|
@ -41,13 +41,13 @@
|
||||
"input.ColorSensor.reflectedLight|block": "%color| reflected light",
|
||||
"input.GyroSensor.angle|block": "%sensor|angle",
|
||||
"input.GyroSensor.rate|block": "%sensor|rotation rate",
|
||||
"input.InfraredSensor.onObjectNear|block": "on %sensor|object within %distance",
|
||||
"input.InfraredSensor.onObjectNear|block": "on %sensor|object near",
|
||||
"input.InfraredSensor.proximity|block": "%infrared|proximity",
|
||||
"input.InfraredSensor.remoteCommand|block": "%infrared|remote command",
|
||||
"input.TouchSensor.isTouched|block": "%sensor|is touched",
|
||||
"input.TouchSensor.onEvent|block": "on %sensor|%event",
|
||||
"input.UltraSonicSensor.distance|block": "%sensor|distance",
|
||||
"input.UltraSonicSensor.onObjectNear|block": "on %sensor|object within %distance|cm",
|
||||
"input.UltraSonicSensor.onObjectNear|block": "on %sensor|object near",
|
||||
"input.buttonDown|block": "brick button down",
|
||||
"input.buttonEnter|block": "brick button enter",
|
||||
"input.buttonLeft|block": "brick button left",
|
||||
|
@ -123,24 +123,25 @@ namespace input {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when an object is getting near
|
||||
* @param distance the proximity, eg: 10
|
||||
* Registers code to run when an object is getting near.
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=input/infrared/on-object-near
|
||||
//% block="on %sensor|object within %distance"
|
||||
//% block="on %sensor|object near"
|
||||
//% blockId=infraredOnObjectNear
|
||||
//% parts="infraredsensor"
|
||||
//% blockNamespace=input
|
||||
//% weight=100 blockGap=8
|
||||
//% distance.min=1 distance.max=95
|
||||
//% group="Infrared Sensor"
|
||||
onObjectNear(distance: number, handler: () => void) {
|
||||
this.proximityThreshold = Math.max(1, Math.min(95, distance));
|
||||
onObjectNear(handler: () => void) {
|
||||
control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
|
||||
if (this.proximity() == PromixityEvent.ObjectNear)
|
||||
control.runInBackground(handler);
|
||||
}
|
||||
|
||||
setObjectNearThreshold(distance: number) {
|
||||
this.proximityThreshold = Math.max(1, Math.min(95, distance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)
|
||||
|
@ -34,24 +34,25 @@ namespace input {
|
||||
|
||||
/**
|
||||
* Registers code to run when the given color is close
|
||||
* @param distance the distance in centimeters when an object is close, eg: 10
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=input/ultrasonic/on-object-near
|
||||
//% block="on %sensor|object within %distance|cm"
|
||||
//% block="on %sensor|object near"
|
||||
//% blockId=ultrasonicOnObjectClose
|
||||
//% parts="infraredsensor"
|
||||
//% blockNamespace=input
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Ultrasonic Sensor"
|
||||
//% distance.min=1 distance.max=250
|
||||
onObjectNear(distance: number, handler: () => void) {
|
||||
this.promixityThreshold = Math.max(1, Math.min(95, distance));
|
||||
control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
|
||||
if (this.distance() == PromixityEvent.ObjectNear)
|
||||
control.runInBackground(handler);
|
||||
}
|
||||
|
||||
setObjectNearThreshold(distance: number) {
|
||||
this.promixityThreshold = Math.max(1, Math.min(250, distance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance from the sonar in millimeters
|
||||
* @param sensor the ultrasonic sensor port
|
||||
|
Loading…
Reference in New Issue
Block a user