Trouble with using encoder and pid library together

You say you are a beginner but you choose to write your own switch handling code rather than using an established library. I will make a small wager I know where the bug(s) are.

I see you using the encoder as an OUTPUT device. I had no idea you could do that and no idea what will happen.

I had coded up a menu system using an encoder for a project earlier this year, but I ended up not using a menu at all. The code was much simpler and certainly no writing to it.

I will follow this thread with interest, maybe this old dog (83) can still learn a new trick.