changeset 4:e2ec8dc3a6d8 default tip

Always empty the receive buffer
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Thu, 15 Sep 2016 00:03:04 +0200
parents ecf4808f2b29
children
files controller.ino servo.fzz
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
Binary file servo.fzz has changed