diff --git a/3d_model/Pointer.stl b/3d_model/Pointer.stl new file mode 100644 index 0000000..071853a Binary files /dev/null and b/3d_model/Pointer.stl differ diff --git a/gauge_vid6008.py b/gauge_vid6008.py index 664f820..86c3183 100644 --- a/gauge_vid6008.py +++ b/gauge_vid6008.py @@ -75,6 +75,7 @@ class Gauge: self._current_step = 0 self._zeroed = False + self._last_dir = None def zero(self): overrun = _OVERRUN_STEPS @@ -128,9 +129,18 @@ class Gauge: self._pin_step.value(0) utime.sleep_us(delay_us) - def steps_toward(self, value, limit=5): - """Return the step delta needed to move toward value, clamped to ±limit.""" - delta = self._val_to_step(value) - self._current_step + def steps_toward(self, value, limit=5, deadband=0.5): + """Return the step delta needed to move toward value, clamped to ±limit. + + deadband: If error is less than this fraction of one step, return 0 to prevent + micro-corrections due to floating-point rounding. Default 0.5 means + no movement if error < half a step. + """ + target_step = self._val_to_step(value) + delta = target_step - self._current_step + deadband_steps = deadband + if abs(delta) < deadband_steps: + return 0 return max(-limit, min(limit, delta)) def get(self):