It seems very strange that I got an e-mail notification only today about this thread by dovegroup's reply.

I am not very good at C but from your example, dovegroup, I think the variable x might change more than one at every step in rotating the encoder because of the bouncing effects.

Ioannis