Created
December 15, 2019 19:22
-
-
Save Mrestof/6d1c27603f045e3942b1a9f8d184cbdf to your computer and use it in GitHub Desktop.
This code checks 10 and 11 digital pins of rotary encoder and add or subtract from counter variable.
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
int counter = 0; | |
bool R, L, END, ROT; | |
bool A, B; | |
bool ff, tf, ft, tt; | |
bool mode = true; | |
void setup() { | |
pinMode(10, INPUT_PULLUP); | |
pinMode(11, INPUT_PULLUP); | |
} | |
void loop() { | |
A = digitalRead(10); | |
B = digitalRead(11); | |
ff = !A && !B; | |
tf = A && !B; | |
ft = !A && B; | |
tt = A && B; | |
if(ft && !(END || R || L)) R = true; | |
if(tf && !(END || R || L)) L = true; | |
if(ff && (R || L)) R = L = END = false; | |
if(tf && R) { | |
R = false; | |
END = ROT = true; | |
} | |
if(ft && L) { | |
L = ROT = false; | |
END = true; | |
} | |
if(tt && END) R = L = END = false; | |
if(ff && END) { | |
END = false; | |
if(ROT) counter += 1; | |
else counter -= 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment