adding a dead band to my motor and gearbox
The simple way is to just subtract one from the other, take the absolute value and see if it exceeds your hysteresis range.

eg.



if (abs (sensorValue - where) &gt;= 0.5) {
  {
  // do something

  if (sensorValue &gt; where)
    {
    // one way
    }
  else
    {
    // other way
    }
  } // end of large enough to worry about




In response to this (since deleted):


  would this not have the same problem as mine as instead of hunting round its target it will just do it 0.5 away from the target? 


By subtracting and taking the absolute value, we create a band of +0.5 and -0.5 where, if the sensor is in that range, we do nothing. It hasn't moved the problem because it can't move in two directions at once (both up and down).