Yep, I have two in my current controller, though one has been removed so I can beta test these: http://www.djtechtools.com/forum/showthread.php?t=25088
They're fairly simple to work with...
Again, this is C, not bascom... but the idea is the same...
Code:
byte read_two_encoders() {
int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_AB1, old_AB2 = 0;
byte rtn = 0;
old_AB1 <<= 2; //remember previous state
old_AB1 |= (ENC_PORT & 0b11); //add current state
old_AB2 <<= 2; //remember previous state
old_AB2 |= (ENC_PORT & 0b1100) >> 2; //add current state
rtn |= (enc_states[(old_AB1 & 0b1111)]) & 0b11;
return rtn | ((enc_states[(old_AB2 & 0b1111)]) & 0b11) << 2;
}
Bookmarks