Diferencia entre revisiones de «Medidor de parpadeo de luz»
Ir a la navegación
Ir a la búsqueda
Página creada con «<pre> const int OVERLOAD_LED = 13; const int COLLECTION_MS = 200; const int DEAD_MS = 100; const int SENSOR_MAX = 800; void setup() { Serial.begin(9600); pinMode(OVERLOAD_LED, OUTPUT); } 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; } digitalWrite(OVERLOAD_LED, x_max > SENSOR_MAX); float…» |
Sin resumen de edición |
||
| Línea 1: | Línea 1: | ||
=Sensor= | |||
* [[Media:Ti opt101.pdf | Texas Instruments OPT101 Hoja de Datos]] | |||
=Codigo= | |||
<pre> | <pre> | ||
Revisión del 21:25 23 jun 2026
Sensor
Codigo
const int OVERLOAD_LED = 13;
const int COLLECTION_MS = 200;
const int DEAD_MS = 100;
const int SENSOR_MAX = 800;
void setup() {
Serial.begin(9600);
pinMode(OVERLOAD_LED, OUTPUT);
}
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;
}
digitalWrite(OVERLOAD_LED, x_max > SENSOR_MAX);
float ratio = (float) x_min / x_max;
Serial.println("0.0 1.0 " + String(ratio));
delay(DEAD_MS);
}