14 template <
int pinD0,
int pinD1,
int pinB>
27 pinMode(pinD0, INPUT_PULLUP);
28 pinMode(pinD1, INPUT_PULLUP);
29 pinMode(pinB, INPUT_PULLUP);
31 attachInterrupt(pinD0, OmRotaryEncoder::isrRe, CHANGE);
32 attachInterrupt(pinD1, OmRotaryEncoder::isrRe, CHANGE);
33 attachInterrupt(pinB, OmRotaryEncoder::isrRe, CHANGE);
35 OmRotaryEncoder::oldD0 = 1;
36 OmRotaryEncoder::oldD1 = 1;
37 OmRotaryEncoder::oldB = 1;
38 OmRotaryEncoder::irqs = 0;
39 OmRotaryEncoder::value4 = 0;
40 OmRotaryEncoder::value = 0;
45 return OmRotaryEncoder::value;
48 static void IRAM_ATTR isrRe()
51 OmRotaryEncoder::irqs++;
53 int d0 = digitalRead(pinD0);
54 int d1 = digitalRead(pinD1);
56 if(OmRotaryEncoder::oldD0 == d0 && OmRotaryEncoder::oldD1 == d1)
return;
60 if(d0 != OmRotaryEncoder::oldD0)
61 dir = d0 == d1 ? +1 : -1;
62 else if(d1 != OmRotaryEncoder::oldD1)
63 dir = d0 != d1 ? +1 : -1;
65 OmRotaryEncoder::value4 += dir;
77 if(OmRotaryEncoder::value4 % 4 == 0)
78 OmRotaryEncoder::value = OmRotaryEncoder::value4 / 4;
80 OmRotaryEncoder::oldD0 = d0;
81 OmRotaryEncoder::oldD1 = d1;