From fbcac7c884cb3e8facda738618278155145c28bb Mon Sep 17 00:00:00 2001 From: Philip Johansson Date: Wed, 15 Jul 2020 19:57:49 +0200 Subject: [PATCH] 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. --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f8f02d4..1f88a0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -272,7 +272,7 @@ SensorData getDist() // https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf const int maxVal = 780; // 60 mm const int minVal = 173; // 800 mm - const int maxValidDist = 610; + const int maxValidDist = 480; const int minValidDist = 70; long dist = map(analogRead(sensorPin), maxVal, minVal, 60, 800); @@ -282,7 +282,7 @@ SensorData getDist() float normalizedDistance = (static_cast(dist) - static_cast(minValidDist)) / static_cast(maxValidDist - minValidDist); - // Serial.printf("Norm dist: %f\n", normalizedDistance); + // Serial.printf("Dist: %d, normalized: %f\n", dist, normalizedDistance); return {.distance = static_cast(dist), .distanceNormalized = normalizedDistance, @@ -299,7 +299,7 @@ void evalDist(SensorData data) static float lastDist = data.distance; - const float stillThreshold = 20.0f; // Distance in mm + const float stillThreshold = 15.0f; // Distance in mm const float releaseThreshold = 70.0f; // If value increases more than this it is considered a release