 
 double goalSpeed = 0;
 float homingSpeed = 3.0;
+bool homed = false;
 
 const int BACKOFF_STEPS = 600; // how many encoder steps to reverse out of endstop (so Zero is this far from the switch)
 

    int p = m.getInt(m.size()-1);
    if (p) {
      if (state==MOTOROFF) {
        state = NOTHOMED;
      }
      motorEnable(true);
    }

      goalSpeed = 0;
      pidSetpoint = encoder0Pos;
      state = OK;
      homed = true;
    }
  }

