|
18 | 18 | by David A Mellis
|
19 | 19 | modified 30 Aug 2011
|
20 | 20 | by Tom Igoe
|
| 21 | + modified 07 Apr 2017 |
| 22 | + by Zachary J. Fields |
21 | 23 |
|
22 | 24 | This example code is in the public domain.
|
23 | 25 |
|
@@ -62,12 +64,12 @@ void loop() {
|
62 | 64 | // read the sensor:
|
63 | 65 | sensorValue = analogRead(sensorPin);
|
64 | 66 |
|
| 67 | + // in case the sensor value is outside the range seen during calibration |
| 68 | + sensorValue = constrain(sensorValue, sensorMin, sensorMax); |
| 69 | + |
65 | 70 | // apply the calibration to the sensor reading
|
66 | 71 | sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
|
67 | 72 |
|
68 | | - // in case the sensor value is outside the range seen during calibration |
69 | | - sensorValue = constrain(sensorValue, 0, 255); |
70 | | - |
71 | 73 | // fade the LED using the calibrated value:
|
72 | 74 | analogWrite(ledPin, sensorValue);
|
73 | 75 | }
|
0 commit comments