 #include <Ticker.h>
+
+#define FLAPCOUNT 62
+//#define FLAPCOUNT 40
 
 #define PIN_TRIAC_N D3
 #define PIN_STROBE D2

#define PIN_EC_3 D0
#define PIN_EC_4 D6
#define PIN_EC_5 D4

uint8_t encoder_val = 0;
uint8_t encoder_desired_val = 0;
volatile int strobe_int = 0;
int timer_running = 0;
Ticker timerReadEncoder;

void setup() {

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

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); // pull down strobe, this lets us read the EC pins
  
  encoder_val = digitalRead(PIN_EC_0);
  encoder_val += digitalRead(PIN_EC_1) << 1;
