diff --git a/libs/color-sensor/color.ts b/libs/color-sensor/color.ts index 63fcd37f..33f61a2b 100644 --- a/libs/color-sensor/color.ts +++ b/libs/color-sensor/color.ts @@ -253,6 +253,11 @@ namespace sensors { //% this.fieldEditor="ports" //% help=sensors/color-sensor/set-threshold setThreshold(condition: Light, value: number) { + // threshold is used in ambient or reflected modes + if (this.mode != LightIntensityMode.Ambient && + this.mode != LightIntensityMode.Reflected) + this.setMode(ColorSensorMode.ReflectedLightIntensity); + if (condition == Light.Dark) this.thresholdDetector.setLowThreshold(value) else @@ -268,7 +273,12 @@ namespace sensors { //% this.fieldEditor="ports" //% help=sensors/color-sensor/threshold threshold(condition: Light): number { - return this.thresholdDetector.threshold(Light.Dark); + // threshold is used in ambient or reflected modes + if (this.mode != LightIntensityMode.Ambient && + this.mode != LightIntensityMode.Reflected) + this.setMode(ColorSensorMode.ReflectedLightIntensity); + + return this.thresholdDetector.threshold(condition); } /** diff --git a/libs/infrared-sensor/ir.ts b/libs/infrared-sensor/ir.ts index bdfbf321..1a11b2eb 100644 --- a/libs/infrared-sensor/ir.ts +++ b/libs/infrared-sensor/ir.ts @@ -279,7 +279,7 @@ namespace sensors { //% group="Threshold" blockGap=8 weight=49 //% this.fieldEditor="ports" proximityThreshold(condition: InfraredSensorEvent): number { - return this._proximityThreshold.threshold(Light.Dark); + return this._proximityThreshold.threshold(condition); } // TODO diff --git a/libs/ultrasonic-sensor/ultrasonic.ts b/libs/ultrasonic-sensor/ultrasonic.ts index 42d4e05c..f0a1c13b 100644 --- a/libs/ultrasonic-sensor/ultrasonic.ts +++ b/libs/ultrasonic-sensor/ultrasonic.ts @@ -115,8 +115,8 @@ namespace sensors { //% this.fieldEditor="ports" threshold(condition: UltrasonicSensorEvent): number { switch (condition) { - case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break; - case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold; break; + case UltrasonicSensorEvent.ObjectNear: return this.promixityThreshold.threshold(ThresholdState.Low); + case UltrasonicSensorEvent.ObjectDetected: return this.movementThreshold; } return 0; }