const int PIN_PUMP = 2; // Pump input
const int PIN_CONSUME = 3; // Consumption input
int tank_level = 0;
unsigned long lastUpdate = 0;
unsigned long lastConsume = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
unsigned long now = millis();
// Pump filling (increase)
if (digitalRead(PIN_PUMP) == HIGH && now - lastUpdate >= 500) {
if (tank_level < 100) tank_level++;
lastUpdate = now;
}
// Consumption draining (decrease)
if (digitalRead(PIN_CONSUME) == HIGH && now - lastConsume >= 1000) {
if (tank_level > 0) tank_level--;
lastConsume = now;
}
// Serial print (so Python can read)
Serial.println(tank_level);
// (keep your HL/HHL/OF/LL/LLL logic here)
}