simplified events

This commit is contained in:
Peli de Halleux
2017-10-26 20:57:18 -07:00
parent 282134f5dc
commit 21b34cb459
4 changed files with 15 additions and 15 deletions

View File

@ -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