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);
}