On Mon, Jun 10, 2013 at 8:07 PM, Joe Wronski w= rote: > On 6/10/2013 10:03 AM, Manu Abraham wrote: >> One thing that I don't understand is, why he does this: " static >> uint8_t old_AB =3D 0;" that would loose the previous state altogether, >> wouldn't it ? > > No, the "=3D0" is only assigned when the static old_AB is allocated and > initialized, after that, it retains it's value as set by the "old_AB =3D" > assignments in read_encoder() Please note the next line: static uint8_t old_AB =3D 0; /**/ old_AB <<=3D 2; //remember previous state Once you initialize the variable to 0, then there is no way that it can remember the previous state. Also note: enc_states[] is a n array with 16 elements in it. Since the array index is & with 0x0f, it makes sense that 4 bits used in th= e array index variable. So, given these; I can't seem to make sense how it remembers the previous state, so that the array index maximum can be reached. Regards, Manu --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .