   attachInterrupt(digitalPinToInterrupt(PIN_STROBE), isr_strobe, FALLING);
 }
 
-void readEncoder(){
+void readEncoder() {
   int prev_val = encoder_val;
+  int oneflip = prev_val - 1;
+  if (oneflip < 1)
+    oneflip = FLAPCOUNT;
+    
   pinMode(PIN_STROBE, OUTPUT);
-  digitalWrite(PIN_STROBE, 0);
+  digitalWrite(PIN_STROBE, 0); // pull down strobe, this lets us read the EC pins
   
   encoder_val = digitalRead(PIN_EC_0);
   encoder_val += digitalRead(PIN_EC_1) << 1;

#include <Ticker.h>

#define PIN_TRIAC_N D3
#define PIN_STROBE D2

#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() {
