     SEN_TRACE("isr: %12lu %12lu start\n",delta,sen_movav1);   
     return; 
   }
-  // Compute the moving average (approximation) of all delta's (but reset moving average after a restart)
+  // Maintain (approximation of) the moving average of all delta's (but initialize moving average after a restart)
   sen_movav1= (sen_count1==0) ? delta : (sen_movav1*SEN_SIZE1 + delta - sen_movav1)/SEN_SIZE1;
   // Bail out if restarting
   if( sen_count1<SEN_COUNT ) {

    SEN_TRACE("isr: %12lu %12lu spike\n",delta,sen_movav1);   
    return;
  }
  // Compute the moving average (approximation) of all delta's (but reset moving average after a restart)
  sen_movav2= (sen_count2==0) ? delta : (sen_movav2*SEN_SIZE2 + delta - sen_movav2)/SEN_SIZE2;
  SEN_TRACE("isr: %12lu %12lu av=%lu\n",delta,sen_movav1,sen_movav2);  
  // Step counter (when warpping, skip 0)
  sen_count2++; 
  if( sen_count2==0 ) sen_count2++; 
}

// Returns the duration of one rotation in us.
// Returns 0 when there is no rotation (detected the last SEN_IDLE us).
unsigned long sen_get(void) {
  unsigned long delta;
  noInterrupts();
    // Get the moving average of the delta's from the isr
    delta= sen_movav2;
    // Check if the last pulse was too old, flag
    if( micros()- sen_time >= SEN_IDLE ) { 
      if( sen_count1>0 ) { SEN_TRACE("isr: end\n"); sen_count1=0; } // sen_count1 is misused to only trace 'end' once
      sen_time = micros()-SEN_IDLE; // Reset sen_time (needed to prevent wrap-around artefacts)
      delta=0;
    }
  interrupts();
  return delta;

// Arduino entry points
// ============================================================

#define BAUD       115200  // Baud rate for serial connection
#define INTRO_MS   3000    // Time (in ms) for the intro message
#define REFRESH_MS 100     // Time (in ms) between display and button refreshes
#define TOGGLE_MS  1000    // Time (in ms) between displaying units and delta (when not rotating)
int units;                 // With the 'flash' button, the units can be chosen. This variable holds the current mode
int olddelta;              // Last valid measurement
unsigned long oldtime;     // Last time the display was refreshed (when not rotating)

void setup() {
  // Initialize serial port (over USB), matrix, sensor en button
  Serial.begin(BAUD);
  dsp_init();
  sen_init();
  but_init();
  // Initialize program variables
  units= 0; // 0=rpm, 1=ms, 2=Hz
  olddelta= 0;
  // Welcome messages
  Serial.printf("\n\nWelcome at mRPM\n");
  dsp_set("mRPM");
  delay(INTRO_MS);
}

void loop(){
