The polled tempo encoder on the xOx large CPU requires proper quadrature decoding.
It is sub-sampled a little when moved very fast, and you don't want to "see" that as a movement in the other direction.
"cnt" is the full resolution (which is four times more than clicks), "tk_value" is what you would apply as delta to your tempo - or in our case here, optionally to several parameters of the performance mode. (That is why I moved out the direct setting of the "new_tempo" variable. )
Code: Select all
static uint8_t last_tk=3;
static int8_t cnt;
uint8_t curr_tk;
curr_tk = TEMPO_PIN & 0x3; // pins A0 and A1
// clicks are on "3"
// CW (+) : 3 -> 1 -> 0 -> 2 -> 3
// CCW (-): 3 -> 2 -> 0 -> 1 -> 3
if(last_tk!=curr_tk)
{ // tempo knob change!
if( (last_tk==3 && curr_tk==1 )
|| (last_tk==1 && curr_tk==0 )
|| (last_tk==0 && curr_tk==2 )
|| (last_tk==2 && curr_tk==3 )
)
{ // valid CW
cnt++;
if(cnt==4)
{
cnt=0;
tk_value++;
}
}
else if(
( last_tk==3 && curr_tk==2 )
|| ( last_tk==2 && curr_tk==0 )
|| ( last_tk==0 && curr_tk==1 )
|| ( last_tk==1 && curr_tk==3 )
)
{ // valid CCW
cnt--;
if(cnt==-4)
{
cnt=0;
tk_value--;
}
}
else // quad err
cnt=0;
last_tk = curr_tk;
}
fortunately we have plenty of code space ...