Diferencia entre revisiones de «Medidor de parpadeo de luz»
Ir a la navegación
Ir a la búsqueda
Sin resumen de edición |
Sin resumen de edición |
||
| Línea 5: | Línea 5: | ||
<pre> | <pre> | ||
#include "I2C_LCD.h" | |||
const int COLLECTION_MS = 200; | const int COLLECTION_MS = 200; | ||
const int | const int SENSOR_LIMIT = 850; | ||
I2C_LCD lcd(39); | |||
void setup() { | void setup() { | ||
Wire.begin(); | |||
Wire.setClock(100000); | |||
lcd.begin(16, 2); | |||
} | } | ||
| Línea 23: | Línea 26: | ||
if (x < x_min) x_min = x; | if (x < x_min) x_min = x; | ||
} | } | ||
float ratio = (float) x_min / x_max; | lcd.clear(); | ||
if (x_max > SENSOR_LIMIT) { | |||
lcd.center(1, "demasiada luz"); | |||
} else { | |||
float ratio = (float)x_min / x_max; | |||
lcd.center(0, ("ratio = " + String(ratio)).c_str()); | |||
} | |||
} | } | ||
</pre> | </pre> | ||
Revisión del 14:38 24 jun 2026
Sensor
Codigo
#include "I2C_LCD.h"
const int COLLECTION_MS = 200;
const int SENSOR_LIMIT = 850;
I2C_LCD lcd(39);
void setup() {
Wire.begin();
Wire.setClock(100000);
lcd.begin(16, 2);
}
void loop() {
int x_max = 0, x_min = 10000;
unsigned long stop_ms = millis() + COLLECTION_MS;
while (millis() < stop_ms) {
int x = analogRead(A0);
if (x > x_max) x_max = x;
if (x < x_min) x_min = x;
}
lcd.clear();
if (x_max > SENSOR_LIMIT) {
lcd.center(1, "demasiada luz");
} else {
float ratio = (float)x_min / x_max;
lcd.center(0, ("ratio = " + String(ratio)).c_str());
}
}