Using a rotary encoder alongside an ic2 display

I wanted to control a Menu, which is shown on a display by using a rotary encoder for navigation.
The display works perfectly, as well as the rotary encoder.
that is if they are in seperate sketches.

Once I try to read the Pin of the rotary encoder inside the sketch which controls the display, the rotary encoder no longer works.

Here is the code of the sketch, thanks in advance!:

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>

#define rotary_pin_A 2
#define rotary_pin_B 3
#define rotary_pin_Push 4

int rotary_state;
int rotary_last_state;

int m1p[4] = {25, 3, 24, 24};
int m2p[4] = {53, 3, 24, 24};
int m3p[4] = {80, 3, 24, 24};
int m4p[4] = {25, 28, 24, 24};
int m5p[4] = {53, 28, 24, 24};
int m6p[4] = {80, 28, 24, 24};

int current_mode = 1;
int current_brightness = 50;
int current_color = 0;
int current_band_level = 1;

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup(void){
pinMode(rotary_pin_A, INPUT);
pinMode(rotary_pin_B, INPUT);
pinMode(rotary_pin_Push, INPUT);
rotary_last_state = digitalRead(rotary_pin_A);
Serial.begin(9600);
u8g2.begin();

}

void loop(void){
rot_state = digitalRead(rotary_pin_A);
Serial.println(rotary_state);

// I think from now on the code is irrelevant for this, since it only controls the display
u8g2.firstPage();
do {
drawConstantLayout();
drawModeFrame();
drawBrightnessIndicator();
drawColorSlider();
drawBandSelector();
} while (u8g2.nextPage());
}
void drawConstantLayout() {
// Initial Layout Setup
u8g2.drawFrame(0, 0, 128, 64);
// Brightness Seperator
u8g2.drawLine(22, 0, 22, 64);
// Color Seperator
u8g2.drawLine(22, 54, 106, 54);
// Lines Seperator
u8g2.drawLine(106, 0, 106, 64);
// Brightness Indicator

u8g2.drawRFrame(6, 15, 10, 45, 1);
// Lamp Symbol --start
u8g2.drawPixel(7, 8);
u8g2.drawPixel(8, 7);
u8g2.drawPixel(9, 5);
u8g2.drawPixel(9, 4);
u8g2.drawPixel(10, 5);
u8g2.drawPixel(10, 4);
u8g2.drawPixel(10, 3);
u8g2.drawPixel(11, 5);
u8g2.drawPixel(11, 4);
u8g2.drawPixel(11, 3);
u8g2.drawPixel(12, 5);
u8g2.drawPixel(12, 4);
u8g2.drawPixel(13, 5);
u8g2.drawPixel(13, 4);
u8g2.drawPixel(12, 3);
u8g2.drawPixel(11, 8);
u8g2.drawPixel(11, 7);
u8g2.drawPixel(14, 7);
u8g2.drawPixel(15, 8);
// Lamp Symbol --end
// O --begin
u8g2.drawPixel(26, 60);
u8g2.drawPixel(27, 61);
u8g2.drawPixel(28, 61);
u8g2.drawPixel(29, 61);
u8g2.drawPixel(30, 60);
u8g2.drawPixel(30, 59);
u8g2.drawPixel(30, 58);
u8g2.drawPixel(29, 57);
u8g2.drawPixel(28, 57);
u8g2.drawPixel(27, 57);
u8g2.drawPixel(26, 58);
u8g2.drawPixel(26, 59);
// O --end
// Color Slide Line
u8g2.drawLine(33, 60, 98, 60);
u8g2.drawPixel(33, 61);
u8g2.drawPixel(98, 61);
// R --begin
u8g2.drawPixel(104, 61);
u8g2.drawPixel(104, 60);
u8g2.drawPixel(103, 59);
u8g2.drawPixel(102, 59);
u8g2.drawPixel(101, 59);
u8g2.drawPixel(101, 60);
u8g2.drawPixel(101, 61);
u8g2.drawPixel(104, 58);
u8g2.drawPixel(103, 57);
u8g2.drawPixel(102, 57);
u8g2.drawPixel(101, 57);
u8g2.drawPixel(101, 58);
// R --end

// Bands --begin
u8g2.drawFrame(111, 5, 13, 6);
u8g2.drawFrame(111, 13, 13, 6);
u8g2.drawFrame(111, 21, 13, 6);
u8g2.drawFrame(111, 29, 13, 6);
u8g2.drawFrame(111, 37, 13, 6);
u8g2.drawFrame(111, 45, 13, 6);
u8g2.drawFrame(111, 53, 13, 6);
// Bands --end
// Only-Light-Mode Logo --begin
u8g2.drawLine(33, 5, 40, 5);
u8g2.drawLine(32, 6, 32, 7);
u8g2.drawLine(31, 8, 31, 10);
u8g2.drawLine(41, 6, 41, 7);
u8g2.drawLine(42, 8, 42, 10);
u8g2.drawLine(32, 11, 41, 11);
u8g2.drawLine(30, 11, 29, 12);
u8g2.drawLine(29, 13, 31, 15);
u8g2.drawPixel(32, 15);
u8g2.drawLine(43, 11, 44, 12);
u8g2.drawLine(44, 13, 42, 15);
u8g2.drawPixel(41, 15);
u8g2.drawLine(33, 16, 40, 16);
u8g2.drawLine(31, 17, 28, 24);
u8g2.drawLine(35, 18, 34, 24);
u8g2.drawLine(38, 18, 39, 24);
u8g2.drawLine(42, 17, 45, 24);
// Only-Light-Mode Logo --end
// Simple Visualizer Logo --begin
u8g2.drawLine(55, 24, 63, 24);
u8g2.drawLine(55, 22, 55, 14);
u8g2.drawLine(57, 22, 57, 19);
u8g2.drawPixel(59, 22);
u8g2.drawLine(61, 22, 61, 21);
u8g2.drawLine(63, 22, 63, 20);
u8g2.drawLine(59, 14, 68, 14);
u8g2.drawLine(66, 12, 68, 14);
u8g2.drawLine(66, 16, 68, 14);
u8g2.drawFrame(71, 7, 3, 18);
u8g2.drawLine(72, 14, 72, 23);
// Simple Viualizer Logo --end
// Ray Visualizer Logo -- begin
u8g2.drawLine(82, 24, 90, 24);
u8g2.drawLine(82, 22, 82, 14);
u8g2.drawLine(84, 22, 84, 19);
u8g2.drawPixel(86, 22);
u8g2.drawLine(88, 22, 88, 21);
u8g2.drawLine(90, 22, 90, 20);
u8g2.drawLine(86, 14, 95, 14);
u8g2.drawLine(93, 12, 95, 14);
u8g2.drawLine(93, 16, 95, 14);
u8g2.drawPixel(100, 5);
u8g2.drawRFrame(99, 6, 3, 5, 1);
u8g2.drawPixel(100, 11);
u8g2.drawRBox(99, 12, 3, 5, 1);
u8g2.drawPixel(100, 17);
u8g2.drawRFrame(99, 18, 3, 5, 1);
u8g2.drawPixel(100, 23);

// Mode selector test
}

/// Just Animation Stuff
void toggleMode(){
if (current_mode != 6){
current_mode = current_mode + 1;
} else {
current_mode = 1;
}
}
void toggleBrightness(){
if(current_brightness != 100){
current_brightness = current_brightness + 10;
} else {
current_brightness = 0;
}
}

void toggleColor(){
if(current_color != 100){
current_color = current_color + 5;
} else {
current_color = 0;
}
}

void toggleBandLevel() {
if(current_band_level != 13) {
current_band_level = current_band_level + 1;
} else {
current_band_level = 1;
}
}

// End of Animation Stuff
void drawModeFrame(){
switch (current_mode){
case 1:
u8g2.drawFrame(m1p[0], m1p[1], m1p[2], m1p[3]);
break;
case 2:
u8g2.drawFrame(m2p[0], m2p[1], m2p[2], m2p[3]);
break;
case 3:
u8g2.drawFrame(m3p[0], m3p[1], m3p[2], m3p[3]);
break;
case 4:
u8g2.drawFrame(m4p[0], m4p[1], m4p[2], m4p[3]);
break;
case 5:
u8g2.drawFrame(m5p[0], m5p[1], m5p[2], m5p[3]);
break;
case 6:
u8g2.drawFrame(m6p[0], m6p[1], m6p[2], m6p[3]);
break;
default:
u8g2.drawFrame(30, 30, 29, 29);
break;
}

}

void drawBrightnessIndicator() {
// Max heights: 15 - 60
int true_height = 59 - (current_brightness * 0.44);
u8g2.drawLine(6, true_height, 15, true_height);

}

void drawColorSlider() {
// Max widths: 33 - 98
int true_width = 33 + current_color * 0.65;
u8g2.drawLine(true_width, 58, true_width, 62);
}

void drawBandSelector() {
if((current_band_level / 7.0) > 1) {
u8g2.drawBox(120, 7 + ((current_band_level - 8) * 8), 2, 2);
u8g2.drawBox(120, 15 + (( current_band_level - 8) * 8), 2, 2);
} else {
u8g2.drawBox(120, 7 + ((current_band_level - 1) * 8), 2, 2);
}
}

Please edit your post and place your code inside code tags. There are guides for doing that in the sticky threads at the top of the forum. That will get rid of the crowd of sunglasses.

You don't seem to have any code to drive the rotary encoder.

You just have the line

 rot_state = digitalRead(rotary_pin_A);

Which is not going to do anything for you.

Use the Encoder libiary you will find at Encoder Library, for Measuring Quadarature Encoded Position or Rotation Signals

When you find yourself writing the same line of code over and over and over, that is a clue that you are missing out on something. Computers do repetitive tasks not programmers. Learn to use for loops and arrays and reduce that huge chain of drawing stuff code to just four lines.

Or, if you are using other people's sketches, seeing the same code patterns repeat over and over is a sign that you should move on and find better code.