     Serial.println (state);
   }
   digitalWrite (pin, state ? HIGH : LOW);
-}
+}
+
+// Set a pin only if the NEW_STATE differs from the OLD_STATE
+inline void diff_pin_set (int pin, bool old_state, bool new_state) {
+  if (old_state != new_state) {
+    pin_set (pin, new_state);
+  }
+}

  return (initial_state == LOW)? false : true;
}

inline void pin_set (int pin, bool state) {
  if (GM_DEBUG) {
    Serial.print ("Setting pin ");

}

inline void update_machine() {
  diff_pin_set (LED_PIN, previous_state.ready, state.ready);
  diff_pin_set (COIN_PIN, previous_state.coin, state.coin); 
  diff_pin_set (CLAW_PIN, previous_state.claw, state.claw);
  diff_pin_set (MOTOR_N_PIN, previous_state.motor_n, state.motor_n);
  diff_pin_set (MOTOR_S_PIN, previous_state.motor_s, state.motor_s);
  diff_pin_set (MOTOR_E_PIN, previous_state.motor_e, state.motor_e);
  diff_pin_set (MOTOR_W_PIN, previous_state.motor_w, state.motor_w);

  previous_state = state;
}

// Initialises digital pin number PIN with a requested MODE and
