diff --git a/gaugemqttcontinuous.py b/gaugemqttcontinuous.py index bd23566..b32a32b 100644 --- a/gaugemqttcontinuous.py +++ b/gaugemqttcontinuous.py @@ -917,21 +917,21 @@ def main(): client_ref.check_msg() - moved_any = False + pending = [] for i, g in enumerate(gauge_objects): - current_target = g._val_to_step(gauge_targets[i]) - if current_target != g._current_step: - direction = 1 if current_target > g._current_step else -1 - steps_to_move = current_target - g._current_step - steps_to_move = max(-5, min(5, steps_to_move)) - for _ in range(abs(steps_to_move)): - g.step(direction) - moved_any = True - was_moving = True + delta = g._val_to_step(gauge_targets[i]) - g._current_step + steps = max(-5, min(5, delta)) + pending.append(steps) + moved_any = any(s != 0 for s in pending) if moved_any: + was_moving = True delay_us = 1_000_000 // MICROSTEPS_PER_SECOND - utime.sleep_us(delay_us) + for tick in range(max(abs(s) for s in pending)): + for i, g in enumerate(gauge_objects): + if tick < abs(pending[i]): + g.step(1 if pending[i] > 0 else -1) + utime.sleep_us(delay_us) else: if was_moving: publish_state(client_ref)