Join Nostr
2025-03-08 22:34:25 UTC
in reply to

Rue Mohr on Nostr: I have a nice little FSM that I like to use with incremental encoders, but I'm not ...

I have a nice little FSM that I like to use with incremental encoders, but I'm not sure it would be fast enough.

#define ERROR 0
signed char offsets[] = {
/* 0000 */ 0,
/* 0001 */ +1,
/* 0010 */ -1,
/* 0011 */ ERROR,
/* 0100 */ -1,
/* 0101 */ 0,
/* 0110 */ ERROR,
/* 0111 */ +1,
/* 1000 */ +1,
/* 1001 */ ERROR,
/* 1010 */ 0,
/* 1011 */ -1,
/* 1100 */ ERROR,
/* 1101 */ -1,
/* 1110 */ +1,
/* 1111 */ 0
};

oldstate = oldstate | (PIND & 0x0C); // Update Oldstate
position += offsets[oldstate]; // Update Position
oldstate = oldstate >> 2;

(pulled from an AVR port of the code)