properly map values

master
shark 6 years ago
parent d0d26492d3
commit a6e18b7bb8

@ -16,7 +16,7 @@ void loop() {
//average += 256-log(256-analogRead(0) / 4) * (256 /5.55); // old linearization
// linearization using resistance to lux relationship
average += (1250000.0 * pow(1023 - analogRead(0), -1.4059) - 73) / 2.08;
average += map(1250000.0 * pow(1023-analogRead(0), -1.4059), 73, 339, 0, 128);
delay(3);
}
average /= ss;
@ -24,10 +24,10 @@ void loop() {
if (oldavg == 0) {
oldavg = average;
}
digitalWrite(13, HIGH);
if (oldavg != average) {
Serial.print("Goal: ");
Serial.println(average);
digitalWrite(13, HIGH);
}
while (oldavg < average) {
oldavg += 1;

Loading…
Cancel
Save