That's normal behavior.
If you are using such a detent type encoder, there are 4 counts for each click.
Do the desired operation once for every four counts.
Change the if conditional expression to execute the desired operation when there is an increase or decrease of 4 or more or -4 or less from oldPos.
Please little thinking about it, for your experience.