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 //average += 256-log(256-analogRead(0) / 4) * (256 /5.55); // old linearization
// linearization using resistance to lux relationship // 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); delay(3);
} }
average /= ss; average /= ss;
@ -24,10 +24,10 @@ void loop() {
if (oldavg == 0) { if (oldavg == 0) {
oldavg = average; oldavg = average;
} }
digitalWrite(13, HIGH);
if (oldavg != average) { if (oldavg != average) {
Serial.print("Goal: "); Serial.print("Goal: ");
Serial.println(average); Serial.println(average);
digitalWrite(13, HIGH);
} }
while (oldavg < average) { while (oldavg < average) {
oldavg += 1; oldavg += 1;

Loading…
Cancel
Save