_ROTTARY_SW_struct.h 989 B

123456
  1. volatile byte aFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
  2. volatile byte bFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
  3. volatile byte encoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
  4. volatile byte oldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
  5. volatile byte reading1 = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
  6. volatile byte reading2 = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent