encoder code question

I know just enough about using the rotary encoder to be dangerous. I have a need for a very simple (to describe but not maybe to code) function that returns one of three values...

0 if the switch is triggered
-1 if turned counter clockwise
1 if turned clockwise.

This seems that it would be a simple thing to do, but I can't even figure out where to start. If anyone has seen any code that might that. I envision calling the function and it just sitting there and doing nothing until one of those three things happens, and then return the result.

Charlie

What switch?

Sorry: On the cheap little encoder board from Amazon, pushing the knob down triggers the switch…

I envision calling the function and it just sitting there and doing nothing until one of those three things happens, and then return the result.

It would be much better for it not to be a blocking function in most circumstances and to return one of several values indicating no change since last called, moved clockwise since last called, moved anticlockwise since last called, switch pressed since last called and switch released since last called.

It actually sounds like a job for an object rather than a function

Google “Arduino KY-40” for lots of tutorials.

To know whether the encoder has turned CW or CCW, you need to fully decode it, and remember the last encoder state.