Fix for self toggling light #6 by lowering the largest accepted distance.

Apparently with brighter LEDs the usable range decreased at the far end.
Also added an improvement on the detection of toggling to be less sensitive. This helps when dimming to not toggle accidentally.
This commit is contained in:
Philip Johansson 2020-07-15 19:57:49 +02:00
parent a4f8106009
commit fbcac7c884

View File

@ -272,7 +272,7 @@ SensorData getDist()
// https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf // https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf
const int maxVal = 780; // 60 mm const int maxVal = 780; // 60 mm
const int minVal = 173; // 800 mm const int minVal = 173; // 800 mm
const int maxValidDist = 610; const int maxValidDist = 480;
const int minValidDist = 70; const int minValidDist = 70;
long dist = map(analogRead(sensorPin), maxVal, minVal, 60, 800); long dist = map(analogRead(sensorPin), maxVal, minVal, 60, 800);
@ -282,7 +282,7 @@ SensorData getDist()
float normalizedDistance = float normalizedDistance =
(static_cast<float>(dist) - static_cast<float>(minValidDist)) / (static_cast<float>(dist) - static_cast<float>(minValidDist)) /
static_cast<float>(maxValidDist - minValidDist); static_cast<float>(maxValidDist - minValidDist);
// Serial.printf("Norm dist: %f\n", normalizedDistance); // Serial.printf("Dist: %d, normalized: %f\n", dist, normalizedDistance);
return {.distance = static_cast<float>(dist), return {.distance = static_cast<float>(dist),
.distanceNormalized = normalizedDistance, .distanceNormalized = normalizedDistance,
@ -299,7 +299,7 @@ void evalDist(SensorData data)
static float lastDist = data.distance; static float lastDist = data.distance;
const float stillThreshold = 20.0f; // Distance in mm const float stillThreshold = 15.0f; // Distance in mm
const float releaseThreshold = const float releaseThreshold =
70.0f; // If value increases more than this it is considered a release 70.0f; // If value increases more than this it is considered a release