20x4 LCD i2c menu with rotary encoder

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction