Diferencia entre revisiones de «Medidor de parpadeo de luz»

Línea 33: Línea 33:
   int x_max = 0, x_min = 10000;
   int x_max = 0, x_min = 10000;
   unsigned long stop_ms = millis() + COLLECTION_MS;
   unsigned long stop_ms = millis() + COLLECTION_MS;
  int sample_count = 0;
   while (millis() < stop_ms) {
   while (millis() < stop_ms) {
     int x = analogRead(A0);
     int x = analogRead(A0);
     if (x > x_max) x_max = x;
     if (x > x_max) x_max = x;
     if (x < x_min) x_min = x;
     if (x < x_min) x_min = x;
    sample_count++;
   }
   }


Línea 48: Línea 50:
     float ratio = (float)x_min / x_max;
     float ratio = (float)x_min / x_max;
     lcd.center(0, ("ratio = " + String(ratio)).c_str());
     lcd.center(0, ("ratio = " + String(ratio)).c_str());
    lcd.center(1, ("samples = " + String(sample_count)).c_str());
   }
   }
}
}
</pre>
</pre>