5 #include <avr/interrupt.h> 13 static volatile bool lastLeftA;
14 static volatile bool lastLeftB;
15 static volatile bool lastRightA;
16 static volatile bool lastRightB;
18 static volatile bool errorLeft;
19 static volatile bool errorRight;
23 static volatile uint16_t countLeft;
24 static volatile uint16_t countRight;
31 countLeft += (lastLeftA ^ newLeftB) - (newLeftA ^ lastLeftB);
33 if((lastLeftA ^ newLeftA) & (lastLeftB ^ newLeftB))
42 static void rightISR()
47 countRight += (lastRightA ^ newRightB) - (newRightA ^ lastRightB);
49 if((lastRightA ^ newRightA) & (lastRightB ^ newRightB))
54 lastRightA = newRightA;
55 lastRightB = newRightB;
58 void Romi32U4Encoders::init2()
69 PCMSK0 = (1 << PCINT4);
75 attachInterrupt(4, rightISR, CHANGE);
96 int16_t counts = countLeft;
106 int16_t counts = countRight;
116 int16_t counts = countLeft;
127 int16_t counts = countRight;
137 bool error = errorLeft;
146 bool error = errorRight;
static bool checkErrorRight()
static bool isInputHigh() __attribute__((always_inline))
Reads the input value of the pin.
static bool checkErrorLeft()
static int16_t getCountsAndResetRight()
static int16_t getCountsRight()
static int16_t getCountsLeft()
static int16_t getCountsAndResetLeft()
static void setInputPulledUp() __attribute__((always_inline))
Sets a pin to be a digital input with the internal pull-up resistor enabled.