# HG changeset patch # User Radomir Dopieralski # Date 1473890584 -7200 # Node ID e2ec8dc3a6d8c8e8c6b7aad0ed6045248611542a # Parent ecf4808f2b2953798615ab5881c7f60c2fb53023 Always empty the receive buffer diff -r ecf4808f2b29 -r e2ec8dc3a6d8 controller.ino --- a/controller.ino Sun Feb 14 19:05:09 2016 +0100 +++ b/controller.ino Thu Sep 15 00:03:04 2016 +0200 @@ -4,7 +4,7 @@ const uint8_t I2C_ADDRESS = 0x09; const uint8_t MAX_PINS = 18; -const uint32_t PWM_PERIOD = 20000L; +const uint32_t PWM_PERIOD = 20000L; // 50Hz volatile uint8_t *ports[MAX_PINS] = { &PORTD, &PORTD, @@ -25,15 +25,15 @@ uint16_t value; } bytes2int; uint8_t servo = Wire.read(); - while (Wire.available() >= 2) { - if (servo >= MAX_PINS) { - return; - } + while ((Wire.available() >= 2) && (servo < MAX_PINS)) { bytes2int.bytes[0] = Wire.read(); bytes2int.bytes[1] = Wire.read(); pwm_set_phase_batch(servo, bytes2int.value); ++servo; } + while (Wire.available()) { + Wire.read(); + } changed = true; } diff -r ecf4808f2b29 -r e2ec8dc3a6d8 servo.fzz Binary file servo.fzz has changed