         }
       }
     }
-    if (running == 0 || errorcode != 0) finished = true;
-  }
-
-
-  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
+  }
+
+
+  int r0 = ARM_DWT_CYCCNT;
+  digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
   int m = micros();
   int n = 100000;
-  while (micros() - m < n) {};
-  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
+  while ((int)micros() - m < n) {};
+  digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
   m = micros();
   n = 900000;
-  while (micros() - m < n) {};
+  while ((int)micros() - m < n) {};
   int r = ARM_DWT_CYCCNT;
   Serial.println(r - r0);
-  Serial.println(micros() - fix);
   Serial.send_now();
 }
-

        if (ci->t.s < 0) {
          if (ci->runlevel == 3) turn_off(ci);
          ci->runlevel = 0;
          runlevel -= 1;
          continue;   // CONTINUE WITH NEXT CHANNEL, THIS ONE IS DONE
        }
        else {

  }
}

void init_wave() {
  for (int i = 0; i < 256; i++) {
    wave[i] = 2047 + (short)round(2047*sin(i * 2 * M_PI));
  }
}

void init_pins() {
  if (waveN > 0) analogWriteResolution(12);
  pinMode(LED_PIN, OUTPUT);
  for (int i = 0; i < digiN; i++) pinMode(digi[i], OUTPUT);
}

void advance(Dura *x, int us) {
  x->u += us;
