Switch to reflected light when calling threshold (#489)
* fix typo * fixing threshold functions * switch to reflected mode when calling threshold
This commit is contained in:
parent
6c253182e4
commit
a4a9af28a4
@ -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(<ThresholdState><number>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(<ThresholdState><number>condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -279,7 +279,7 @@ namespace sensors {
|
||||
//% group="Threshold" blockGap=8 weight=49
|
||||
//% this.fieldEditor="ports"
|
||||
proximityThreshold(condition: InfraredSensorEvent): number {
|
||||
return this._proximityThreshold.threshold(<ThresholdState><number>Light.Dark);
|
||||
return this._proximityThreshold.threshold(<ThresholdState><number>condition);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user