Created
July 28, 2022 16:05
-
-
Save jayrhynas/f87df2e7fcd3a669a2fa8a3b36d7d250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Encoder { | |
... | |
int32_t *_currentPosition; | |
... | |
} | |
Encoder::Encoder(int32_t *currentPosition, uint8_t ENCA, uint8_t ENCB) { | |
_ENCA = ENCA; | |
_ENCB = ENCB; | |
_currentPosition = currentPosition; | |
pinMode(_ENCA, INPUT_PULLUP); | |
pinMode(_ENCB, INPUT_PULLUP); | |
attachInterrupt(digitalPinToInterrupt(_ENCA), updateEncoder, RISING); | |
} | |
void Encoder::updateEncoder() { | |
if (digitalRead(_ENCB) > 0) { | |
*_currentPosition++; | |
} else { | |
*_currentPosition--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment