First things first I am completely new to electronics, Arduino and C programming.
Anyways without getting into too much explanation of how I got to where I am now or my end project goal I will jump right into my question as I am sure it will be an easy answer for most of you.
I am trying to do the direct port manipulation to keep track of a rotary encoder. After a lot of searching the internet, I found this website http://nick.borko.org/blog/2011/03/deco ... y-encoder/ his code(posted below) does the closest thing to what I want that I could find except what I want is just slightly different.
Code: Select all
volatile boolean rotating = false;
static boolean rotating_cw = false;
void rotEncoder() {
byte in = PIND & B1100;
rotating_cw = in == B1100;
rotating = in & B100;
}
int readEncoder() {
int dir = rotating ? (rotating_cw ? 1 : -1) : 0;
rotating = false;
return dir;
}
void setup() {
DDRD |= B1100;
PORTD |= B1100;
attachInterrupt(0, rotEncoder, CHANGE); // ISR for rotary encoder
rotating = false; // ignore the first reading, which will be false
}
What I want is just one interrupt function that just +1 or -1 to a continuous counter.
My rotary encoder is hooked up to pins 2 and 3. Hopefully, this is enough information to answer my question but if not just let me know.
Bonus points to anyone who can explain to me what the heck all his bit math means. lol