Skip to content

Commit 5edbf4b

Browse files
committed
Update 04.Analog/Calibrate.ino
Calibrate generated values beyond the from range of the map function and the behavior did not seem to match the spirit of the comments.
1 parent 647a1b0 commit 5edbf4b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

build/shared/examples/03.Analog/Calibration/Calibration.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
By David A Mellis
2020
modified 30 Aug 2011
2121
By Tom Igoe
22+
modified 07 Apr 2017
23+
By Zachary J. Fields
2224
2325
http://www.arduino.cc/en/Tutorial/Calibration
2426
@@ -64,11 +66,11 @@ void loop() {
6466
// read the sensor:
6567
sensorValue = analogRead(sensorPin);
6668

67-
// apply the calibration to the sensor reading
68-
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
69-
7069
// in case the sensor value is outside the range seen during calibration
71-
sensorValue = constrain(sensorValue, 0, 255);
70+
sensorValue = constrain(sensorValue, sensorMin, sensorMax);
71+
72+
// apply the calibration to the sensor reading
73+
sensorValue = map(sensorValue, 0, 1023, 0, 255);
7274

7375
// fade the LED using the calibrated value:
7476
analogWrite(ledPin, sensorValue);

0 commit comments

Comments
 (0)