   void off() { stateChange(false); } // drain time
   void step(monitor_t* now, char cycleMins) {   // check conditions and adjust
     dbg(valveDBG, "\nvalve[].step - number = "); dln(valveDBG, number);
-    if(!filling && ( startTime <= millis() )) { // time to start filling
+    int t = millis();
+    dbg(valveDBG, "t = "); dln(valveDBG, t);
+    if(filling && ( lastFlip + (floodMins * 60 * 1000) ) <= t) { // flood over
+      dbg(valveDBG, "t = "); dln(valveDBG, t);
+      dbg(valveDBG, "lastFlip = "); dln(valveDBG, lastFlip);
+      dbg(valveDBG, "floodMins = "); dln(valveDBG, floodMins);
+      dbg(valveDBG, "floodMins * 60 * 1000 = ");
+      dln(valveDBG, floodMins * 60 * 1000);
+      off();
+    } else if(!filling && ( startTime <= t )) { // time to start filling
       on();
       startTime += (cycleMins * 60 * 1000);
       dbg(valveDBG, "startTime = "); dln(valveDBG, startTime);
-    } else if(filling && full(now)) {           // we're full
+    }
+    /* old version using level sensors:
+    else if(filling && full(now)) {           // we're full
       off();
-    } // TODO if cycleMins - dryMins ...?
+    } 
+    */
   }
 int averageLevel1 = 22; // TODO
 int averageLevel2 = 22;

  int fillLevel = 10;           // cms below the level sensor: drain point
  bool filling = false;         // true when closed / on
  long lastFlip = -1;           // millis at last state change

  Valve() { number = counter++; }
  void stateChange(bool newState) { // turn on or off

class FlowController { // the set of valves and their config ////////////////
  public:
  int numValves = 3;         // WARNING! call init if resetting!
  int cycleMins = 3; // TODO// how long is a flood/drain cycle?
  int maxSimultDrainers = 1; // how many beds can drain simultaneously?
  int minBedsWet = 1;        // min beds that are full or filling
  int maxBedsWet = 2;        // max beds that are full or filling
