   encoder_val += digitalRead(PIN_EC_4) << 4;
   encoder_val += digitalRead(PIN_EC_5) << 5;
   
-  pinMode(PIN_STROBE, INPUT);
-
-  if(encoder_val == 63 || encoder_val != prev_val + 1){
-    timerReadEncoder.once_ms(1, readEncoder);
+  if (encoder_val == 63 || encoder_val != oneflip) { // re-trigger a read if we read an unexpected result. this eliminates the need for real-time finetuning of the read interval.
+    encoder_val = prev_val;
+    timerReadEncoder.once_ms(ENCODER_REREAD_DELAY, readEncoder);
+    read_error_count++;
     return;
   }
 
-  if(encoder_val == encoder_desired_val){
-    digitalWrite(PIN_TRIAC_N, 1); 
+  if (encoder_val == encoder_desired_val) {
+    digitalWrite(PIN_TRIAC_N, 1);  // stop the motor when we have reached the desired position.
   }
    
-  timer_running = 0;
+  pinMode(PIN_STROBE, INPUT); // strobe back to input, this allows the interrupt to be triggered
+  timer_running = false;
   strobe_int = 0;
 }
 
-void isr_strobe(){
+void isr_strobe() {
   strobe_int++;
 }
 
 void loop() {
-  static int prev_val = 0;
-  static int display_pos = 1;
+  static int prev_val = 0; // just for printing changes
   
-  if(strobe_int > 0 && timer_running < 1){
-    timer_running++;
-    timerReadEncoder.once_ms(8, readEncoder);
+  if (strobe_int > 0 && !timer_running) {
+    timer_running = true;
+    timerReadEncoder.once_ms(STROBE_READ_DELAY, readEncoder);
+  }
+
+  if (strobe_int > 1) {
+    Serial.print("b/o ");Serial.println(strobe_int); // bounce or overrun
+  }
+  if (read_error_count > 0) {
+    Serial.print("re ");Serial.println(read_error_count);
+    read_error_count = 0;
   }
   
-  if(encoder_val != prev_val && encoder_val != 63){ 
+  if (encoder_val != prev_val) { 
     Serial.println(encoder_val);
     prev_val = encoder_val;
-  }
-
-  if(encoder_val != encoder_desired_val){
-    digitalWrite(PIN_TRIAC_N, 0);
-  }else{
-    digitalWrite(PIN_TRIAC_N, 1);
   }
   
   if (Serial.available() > 0) {
     char ch = Serial.read();
-    if(ch == 'a')
+    if (ch == 'a')
       encoder_desired_val++;
-    if(ch == 's')
+    if (ch == 's')
       encoder_desired_val--;
-    if(encoder_desired_val < 1)encoder_desired_val=62;
-    if(encoder_desired_val > 62)encoder_desired_val=1;
-    if(ch == 'x')
+    if (encoder_desired_val < 1)
+      encoder_desired_val = FLAPCOUNT;
+    if (encoder_desired_val > FLAPCOUNT)
+      encoder_desired_val = 1;
+    if (ch == 'x')
       digitalWrite(PIN_TRIAC_N, 1);
-    if(ch == 'y')
+    if (ch == 'y')
       digitalWrite(PIN_TRIAC_N, 0);
   }
 }

  attachInterrupt(digitalPinToInterrupt(PIN_STROBE), isr_strobe, FALLING);
}

void readEncoder(){
  int prev_val = encoder_val;
  pinMode(PIN_STROBE, OUTPUT);
  digitalWrite(PIN_STROBE, 0);
  
  encoder_val = digitalRead(PIN_EC_0);
  encoder_val += digitalRead(PIN_EC_1) << 1;

#define PIN_EC_3 D0
#define PIN_EC_4 D6
#define PIN_EC_5 D4
#define STROBE_READ_DELAY 30
#define ENCODER_REREAD_DELAY 4

volatile int read_error_count = 0;
volatile uint8_t encoder_val = 1; // last read value
uint8_t encoder_desired_val = 1; // value to stop at
volatile int strobe_int = 0; // interrupt counter
bool timer_running = false; // a timer is active, don't start a new one
Ticker timerReadEncoder;

void setup() {
