OLED screen page adding problem

I'm having a problem with my AI project, which I control using an Arduino Nano, a 1.3-inch OLED display, and a rotary encoder. There are six pages. When I try to add the seventh page, all the text gets mixed up (as in the example image). Since I don't have any coding knowledge, I wanted to ask for your help. Thank you!

#include <Wire.h>
#include <U8g2lib.h>
#include <EEPROM.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_ADDRESS 0x3C

// OLED ekran tanımlaması
U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// Bekleme görseli (128x64px)
const unsigned char epd_bitmap_trh__2_ [] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3f, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3e, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x83, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x80, 0x83, 0x07, 0x1e, 0x3c, 0xfc, 0x3f, 0x1c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x07, 0x1e, 0x3c, 0xfc, 0x3f, 0x0c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x07, 0x1e, 0x3c, 0xfc, 0x3f, 0x04, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3c, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3e, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x3f, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xfe, 0x3f, 0x7c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xfe, 0x0f, 0x7c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xfe, 0x0f, 0x7c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Direksiyon görseli (128x45px)
const unsigned char epd_bitmap_ster [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xc7, 0x03, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x07, 0x0e, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x07, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x07, 0x60, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x07, 0xc0, 0x00, 
  0x00, 0x00, 0x0c, 0x00, 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc0, 0x1f, 0x80, 0x01, 
  0x80, 0x3f, 0x0c, 0x00, 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x78, 0xf0, 0x00, 0x03, 
  0x80, 0xf1, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0e, 0x80, 0x03, 0x06, 
  0x80, 0xe1, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00, 0x06, 0x0c, 
  0x80, 0xc1, 0xed, 0xf7, 0xbb, 0xf7, 0xfd, 0x98, 0x9f, 0x3f, 0x80, 0xc0, 0x01, 0x00, 0x1c, 0x08, 
  0x80, 0xc1, 0xed, 0xb9, 0xbb, 0xbb, 0xfd, 0xdc, 0xbd, 0x7f, 0xc0, 0x40, 0x00, 0x00, 0x10, 0x18, 
  0x80, 0xc1, 0xed, 0x18, 0xff, 0x39, 0xdc, 0xfc, 0xb8, 0x73, 0x40, 0x60, 0x00, 0x00, 0x30, 0x10, 
  0x80, 0xc1, 0xed, 0xfc, 0xff, 0xf8, 0xdc, 0xed, 0xb0, 0x63, 0x60, 0x30, 0x00, 0x00, 0x60, 0x30, 
  0x80, 0xc1, 0xed, 0x1c, 0xf8, 0xe0, 0xdd, 0xef, 0xb0, 0x63, 0x20, 0x10, 0x00, 0x00, 0x40, 0x20, 
  0x80, 0xe1, 0xec, 0x18, 0xf8, 0x81, 0x9d, 0xe7, 0xb8, 0x63, 0x20, 0x18, 0xc0, 0x1f, 0xc0, 0x20, 
  0x80, 0x79, 0xec, 0x38, 0xbb, 0x9b, 0x9d, 0xc7, 0xb9, 0x63, 0x30, 0x08, 0x78, 0xf0, 0x80, 0x60, 
  0x80, 0x3f, 0xec, 0xf0, 0x3b, 0xff, 0x1d, 0x87, 0x9f, 0x63, 0x10, 0xf8, 0x0f, 0x80, 0xff, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x1c, 0x00, 0x00, 0xc0, 0x41, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x07, 0x00, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x08, 0x00, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x00, 0x40, 0x10, 0x00, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x10, 0x00, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xe0, 0x4f, 0x90, 0x3f, 0x40, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x3c, 0x88, 0x88, 0xe0, 0x41, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x18, 0xc7, 0x80, 0x40, 
  0x00, 0xe0, 0x0f, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x30, 0x08, 0x10, 0x40, 0x80, 0x60, 
  0x00, 0xf8, 0x1f, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x10, 0x40, 0xc0, 0x20, 
  0x00, 0x78, 0x1c, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x30, 0x60, 0x40, 0x20, 
  0x00, 0x1c, 0xb8, 0xff, 0xfd, 0xcc, 0xcf, 0xff, 0xf3, 0x03, 0x60, 0x30, 0x20, 0x20, 0x60, 0x30, 
  0x00, 0x1c, 0xb8, 0x63, 0xec, 0xcc, 0xce, 0xfd, 0xb3, 0x03, 0x40, 0x60, 0x20, 0x20, 0x30, 0x10, 
  0x00, 0x1c, 0xb8, 0x61, 0xc0, 0x0d, 0xdc, 0x39, 0x03, 0x07, 0xc0, 0x40, 0x20, 0x20, 0x10, 0x18, 
  0x00, 0x1c, 0xb8, 0x61, 0xfc, 0xcd, 0xdf, 0x18, 0xf3, 0x07, 0x80, 0xc0, 0x61, 0x30, 0x1c, 0x08, 
  0x00, 0x1c, 0xb8, 0x61, 0xce, 0xed, 0xdd, 0x18, 0x3b, 0x07, 0x80, 0x01, 0x43, 0x10, 0x06, 0x0c, 
  0x00, 0x38, 0x9c, 0x61, 0xc6, 0xed, 0xdc, 0x18, 0x3b, 0x07, 0x00, 0x03, 0x4e, 0x90, 0x03, 0x06, 
  0x00, 0xf8, 0x9f, 0xe1, 0xe6, 0xed, 0xde, 0x18, 0xbb, 0x07, 0x00, 0x06, 0x78, 0xf0, 0x00, 0x03, 
  0x00, 0xe0, 0x87, 0xe1, 0xfd, 0xcd, 0xdf, 0x18, 0xf3, 0x07, 0x00, 0x0c, 0x40, 0x10, 0x80, 0x01, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0xc0, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x60, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0e, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xc0, 0x03, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Rotary Encoder pinleri
const int CLK_PIN = 2;  // CLK pin
const int DT_PIN = 4;   // DT pin
const int SW_PIN = 8;   // Switch pin

// EEPROM adresleri
#define EEPROM_INITIALIZED_FLAG 0
#define EEPROM_VALUES_START 1
#define INITIALIZED_VALUE 123

// Menü değişkenleri
int currentPage = 0;     // Aktif sayfa
int totalPages = 6;      // Toplam sayfa sayısı
bool inSettingMode = false;  // Ayar modunda mı?
int currentValue = 50;    // Başlangıç değeri (%50)
int lastValue = 50;
int savedValues[4] = {50, 50, 50, 50};  // Her sayfa için kaydedilen değerler
int centerState = 0;     // Ortalama işlemi durumu (0: Ana ekran, 1: Talimat ekranı)
bool isInIdleScreen = false; // Bekleme ekranında mı?
int selectedDegree = 0;  // Seçili derece indeksi (0: 270°, 1: 900°, 2: 1080°)
const int degreeOptions[] = {270, 900, 1080};  // Derece seçenekleri

// Sayfa isimleri
const char* pageNames[] = {
  "",
  "Tum Ayar",
  "Constant",
  "Yay Ayar",
  "Damper",
  "Derece"
};

// Durum değişkenleri
int lastCLKState;
bool buttonPressed = false;
unsigned long lastButtonPress = 0;
unsigned long lastActivityTime = 0;
const unsigned long debounceDelay = 100;  // Debounce süresini 200ms'ye çıkardım
const unsigned long idleTimeout = 15000;  // Bekleme süresi 15 saniye

void setup() {
  Serial.begin(9600);  // Leonardo ile haberleşme için
  
  // I2C hızını artır
  Wire.setClock(400000L);  // I2C hızını 400kHz'e çıkar
  
  // EEPROM'dan değerleri yükle
  loadValuesFromEEPROM();
  
  // Rotary Encoder pin modları
  pinMode(CLK_PIN, INPUT);
  pinMode(DT_PIN, INPUT);
  pinMode(SW_PIN, INPUT_PULLUP);
  
  lastCLKState = digitalRead(CLK_PIN);
  lastActivityTime = millis();

  // OLED ekran başlatma
  display.begin();
  display.enableUTF8Print();  // Türkçe karakter desteği
  display.setFont(u8g2_font_6x12_tr);  // Temel font ayarı
  display.setFontRefHeightExtendedText();
  display.setDrawColor(1);
  display.setFontPosTop();
  display.setFontDirection(0);
  
  updateDisplay();
}

void loadValuesFromEEPROM() {
  // EEPROM ilk kez kullanılıyorsa başlangıç değerlerini kaydet
  if (EEPROM.read(EEPROM_INITIALIZED_FLAG) != INITIALIZED_VALUE) {
    EEPROM.write(EEPROM_INITIALIZED_FLAG, INITIALIZED_VALUE);
    for (int i = 0; i < 4; i++) {
      EEPROM.write(EEPROM_VALUES_START + i, 50);  // Varsayılan değer %50
      savedValues[i] = 50;
    }
  } else {
    // EEPROM'dan değerleri oku
    for (int i = 0; i < 4; i++) {
      savedValues[i] = EEPROM.read(EEPROM_VALUES_START + i);
    }
  }
  // Aktif sayfanın değerini ayarla
  currentValue = savedValues[currentPage];
}

void saveValueToEEPROM(int page, int value) {
  if (page >= 0 && page < 4) {
    EEPROM.write(EEPROM_VALUES_START + page, value);
    savedValues[page] = value;
  }
}

void loop() {
  unsigned long currentTime = millis();
  bool activity = false;
  
  // Rotary Encoder kontrolü
  if (!isInIdleScreen && checkEncoder()) {  // Bekleme ekranında değilse encoder'ı kontrol et
    activity = true;
  }
  
  // Buton kontrolü
  if (checkButton()) {
    if (isInIdleScreen) {  // Bekleme ekranındaysa
      isInIdleScreen = false;  // Bekleme ekranından çık
      activity = true;  // Aktiviteyi işaretle
      lastActivityTime = currentTime;  // Son aktivite zamanını güncelle
      updateDisplay();  // Ekranı hemen güncelle
      return;  // Döngüden çık
    } else if (currentPage == 0) {  // CENTER sayfası için
      if (centerState == 0) {
        centerState = 1;
      } else if (centerState == 1) {
        Serial.write("center\n");
        centerState = 0;
      }
      activity = true;
    } else {
      inSettingMode = !inSettingMode;
      activity = true;
      
      if (!inSettingMode) {
        if (currentPage >= 1 && currentPage <= 4) {
          // Ayar modundan çıkıldığında değeri gönder
          int mappedValue = map(currentValue, 0, 100, 1, 500);  // Yüzdeyi 1-500 aralığına dönüştür
          char command[20];
          int gainIndex;
          
          // Sayfa numarasına göre gain index'ini belirle
          switch(currentPage) {
            case 1: gainIndex = 0; break;  // Tüm Ayarlar
            case 2: gainIndex = 1; break;  // Constant
            case 3: gainIndex = 8; break;  // Yay Ayarı
            case 4: gainIndex = 9; break;  // Damper Ayarı
            default: gainIndex = 0; break;
          }
          
          // Gain komutunu gönder
          sprintf(command, "gain %d %d\n", gainIndex, mappedValue);
          Serial.write(command);  // Leonardo'ya gönder
          
          // Save komutunu gönder
          delay(50);  // Komutlar arası kısa bir bekleme
          Serial.write("save\n");  // Leonardo'ya save komutu gönder
          
          // EEPROM'a kaydet
          saveValueToEEPROM(currentPage - 1, currentValue);  // İndeks 1 azaltıldı
        } else if (currentPage == 5) {  // Derece sayfası için
          // Seçili dereceyi gönder
          char command[20];
          sprintf(command, "range %d\n", degreeOptions[selectedDegree]);
          Serial.write(command);
          
          // Save komutunu gönder
          delay(50);
          Serial.write("save\n");
        }
      }
    }
  }
  
  // Sayfa değiştiğinde
  static int lastPage = -1;
  if (lastPage != currentPage) {
    if (currentPage >= 1 && currentPage <= 4) {  // Değer sayfaları için
      currentValue = savedValues[currentPage - 1];  // İndeks 1 azaltıldı
    }
    lastPage = currentPage;
    centerState = 0;  // Sayfa değiştiğinde center durumunu sıfırla
    activity = true;
  }
  
  // 5 saniye hareketsizlik kontrolü
  if (!isInIdleScreen && currentTime - lastActivityTime >= idleTimeout) {
    isInIdleScreen = true;  // Bekleme ekranına geçildiğini işaretle
    showIdleScreen();
  }
  
  // Aktivite varsa ve bekleme ekranında değilse ekranı güncelle
  if (activity && !isInIdleScreen) {
    lastActivityTime = currentTime;
    updateDisplay();
  }
}

bool checkEncoder() {
  int currentCLKState = digitalRead(CLK_PIN);
  int dtState = digitalRead(DT_PIN);
  static unsigned long lastEncoderTime = 0;
  unsigned long currentTime = millis();
  bool changed = false;
  
  if (currentCLKState != lastCLKState && currentCLKState == HIGH) {
    unsigned long encoderInterval = currentTime - lastEncoderTime;
    lastEncoderTime = currentTime;
    
    // Dönüş hızını hesapla
    int dynamicStep;
    if (encoderInterval < 100) {  // Hızlı dönüş
      dynamicStep = 3;  // Hızlı artış
    } else {  // Normal dönüş
      dynamicStep = 1;  // Yavaş artış
    }
    
    if (dtState != currentCLKState) {
      if (inSettingMode) {
        if (currentPage >= 1 && currentPage <= 4) {
          currentValue = max(0, currentValue - dynamicStep);
        } else if (currentPage == 5) {
          selectedDegree = (selectedDegree - 1 + 3) % 3;
        }
      } else if (!inSettingMode) {
        currentPage = (currentPage - 1 + totalPages) % totalPages;
      }
      changed = true;
    } else {
      if (inSettingMode) {
        if (currentPage >= 1 && currentPage <= 4) {
          currentValue = min(100, currentValue + dynamicStep);
        } else if (currentPage == 5) {
          selectedDegree = (selectedDegree + 1) % 3;
        }
      } else if (!inSettingMode) {
        currentPage = (currentPage + 1) % totalPages;
      }
      changed = true;
    }
  }
  
  lastCLKState = currentCLKState;
  return changed;
}

bool checkButton() {
  if (digitalRead(SW_PIN) == LOW) {
    if (!buttonPressed && (millis() - lastButtonPress) > debounceDelay) {
      buttonPressed = true;
      lastButtonPress = millis();
      return true;
    }
  } else {
    buttonPressed = false;
  }
  return false;
}

void updateDisplay() {
  display.clearBuffer();
  
  if (currentPage == 0 && centerState == 1) {  // CENTER sayfası için
    // Ortalama talimat ekranı
    display.setFont(u8g2_font_10x20_tr);  // Daha büyük font
    
    const char* message = "DIREKSIYONU";
    int w = display.getStrWidth(message);
    display.drawStr((SCREEN_WIDTH - w) / 2, 8, message);
    
    const char* message2 = "ORTALAYIN VE";
    w = display.getStrWidth(message2);
    display.drawStr((SCREEN_WIDTH - w) / 2, 28, message2);
    
    const char* message3 = "BUTONA BASIN";
    w = display.getStrWidth(message3);
    display.drawStr((SCREEN_WIDTH - w) / 2, 48, message3);
  } else {
    // Normal sayfa gösterimi
    if (currentPage == 0) {
      display.setFont(u8g2_font_6x12_tr);  // Küçük font
    } else {
      display.setFont(u8g2_font_10x20_tr);  // Büyük font
    }
    
    // Başlığı yazdır
    const char* title = pageNames[currentPage];
    int w = display.getStrWidth(title);
    display.drawStr((SCREEN_WIDTH - w) / 2, 0, title);
    
    if (currentPage >= 1 && currentPage <= 4) {
      // Değer gösterimi
      display.setFont(u8g2_font_7x14_tr);  // Orta boy font
      char valueText[15];
      sprintf(valueText, "Deger: %%%d", currentValue);
      display.drawStr(2, 18, valueText);
      
      // Progress bar
      int barHeight = 32;
      int barY = 30;
      
      // Progress bar çerçevesi
      display.drawFrame(0, barY, SCREEN_WIDTH - 1, barHeight);
      
      // Progress bar dolgusu
      int barWidth = map(currentValue, 0, 100, 0, SCREEN_WIDTH - 2);
      
      if (currentPage == 1) { // Tüm Ayarlar sayfası için özel görünüm
        int threshold75 = map(75, 0, 100, 0, SCREEN_WIDTH - 2);
        
        // %75'e kadar olan kısım normal dolgu
        if (barWidth > 0) {
          display.drawBox(1, barY + 1, min(barWidth, threshold75), barHeight - 2);
        }
        
        // %75'ten sonrası için çizgili desen
        if (barWidth > threshold75) {
          int startX = threshold75 + 1;
          int patternWidth = barWidth - threshold75;
          
          // Çizgili desen çizimi
          for (int x = startX; x < startX + patternWidth; x += 3) {
            display.drawVLine(x, barY + 1, barHeight - 2);
          }
        }
      } else {
        // Diğer sayfalar için normal dolgu
        if (barWidth > 0) {
          display.drawBox(1, barY + 1, barWidth, barHeight - 2);
        }
      }
    } else if (currentPage == 0 && centerState == 0) {
      // CENTER sayfası ana ekran - direksiyon görseli
      int imageHeight = 45;
      int yPos = (SCREEN_HEIGHT - imageHeight) / 2;
      display.drawXBMP(0, yPos, 128, imageHeight, epd_bitmap_ster);
    } else if (currentPage == 5) { // Derece sayfası
      display.setFont(u8g2_font_10x20_tr);  // Büyük font
      
      // Her seçenek için
      for (int i = 0; i < 3; i++) {
        char degreeText[15];
        sprintf(degreeText, "%d\xB0", degreeOptions[i]);  // \xB0 derece işareti için ASCII kodu
        
        // Y pozisyonlarını ayarla (üstten 15px boşluk, aralarında 16px boşluk)
        int yPos = 15 + (i * 16);
        
        // Seçili seçeneği vurgula
        if (inSettingMode && i == selectedDegree) {
          display.setDrawColor(1);
          display.drawBox(10, yPos - 2, 108, 16);  // Kutu boyutunu ayarladım
          display.setDrawColor(0);
          display.drawStr(15, yPos, degreeText);
          display.setDrawColor(1);
        } else {
          display.drawStr(15, yPos, degreeText);
        }
      }
    }
  }
  
  display.sendBuffer();
}

void showIdleScreen() {
  display.clearBuffer();
  display.drawXBMP(0, 0, 128, 64, epd_bitmap_trh__2_);
  display.sendBuffer();
}


When I compile your code I get the below error

Compilation error: 'updateDisplay' was not declared in this scope

I edited it. Is it fixed?

It now compiles. Your problem is more than likely that you are very low on free RAM.

Sketch uses 19842 bytes (64%) of program storage space. Maximum is 30720 bytes.
Global variables use 1918 bytes (93%) of dynamic memory, leaving 130 bytes for local variables. Maximum is 2048 bytes.

You've seen the codes. Is there a way to increase the RAM without disrupting its functionality?

You have a number of serial writes for fixed text; use serial.print and the F macro.

You have an array with pageNames that can be stored in PROGMEM.

If it's sufficient to get sufficient free memory is another question.