Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01de945

Browse files
zfieldsper1234
authored andcommitted
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 b3da224 commit 01de945

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎examples/03.Analog/Calibration/Calibration.ino‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
by David A Mellis
1919
modified 30 Aug 2011
2020
by Tom Igoe
21+
modified 07 Apr 2017
22+
by Zachary J. Fields
2123
2224
This example code is in the public domain.
2325
@@ -62,12 +64,12 @@ void loop() {
6264
// read the sensor:
6365
sensorValue = analogRead(sensorPin);
6466

67+
// in case the sensor value is outside the range seen during calibration
68+
sensorValue = constrain(sensorValue, sensorMin, sensorMax);
69+
6570
// apply the calibration to the sensor reading
6671
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
6772

68-
// in case the sensor value is outside the range seen during calibration
69-
sensorValue = constrain(sensorValue, 0, 255);
70-
7173
// fade the LED using the calibrated value:
7274
analogWrite(ledPin, sensorValue);
7375
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /