When moving to a new screen, I want to erase the buttons and labels from the previous screen

Description

When the power is turned on, the clock screen is displayed.

Added a button to move to the settings screen.

When I press this button, I want to move to the numeric keypad panel screen, but the numeric keypad panel is now displayed, but the previous clock display screen remains as is.

What MCU/Processor/Board and compiler are you using?

ESP32 + ili9488

What do you want to achieve?

Please tell me how to delete the object on the previous screen.

Also, if you have any basic code for using lvgl for screen transitions, please let me know.

Is my method a little funny?

What have you tried so far?

my code on github

Code to reproduce

Add the relevant code snippets here.

static void btn_event_setting_cb(lv_event_t *event) {
    
    Serial.println("設定ボタン_イベントハンドラ呼び出し");
    lv_event_code_t code = lv_event_get_code(event);
    if (code == LV_EVENT_CLICKED) {
        Serial.println("設定ボタンがクリックされました");

        //lv_obj_set_visible(time_label,false); // ボタンオブジェクトを削除
        //lv_obj_set_visible(wifiStatus_label,false); // ボタンオブジェクトを削除
        //lv_obj_set_visible(settings_btn,false); // ボタンオブジェクトを削除
        tenkey_setup();
    }
}



LV_FONT_DECLARE(jpFont04);



void clock_setup() {
    Serial.begin(115200); // シリアル通信の初期化
    Serial.println("clock_setup Start");

    // TFTの初期化
    tft.begin();
    tft.setRotation(1);

    uint16_t calData[5] = { 231, 3567, 344, 3355, 7 };
    tft.setTouch(calData);

    // LVGLの初期化
    lv_init();

    // バッファのサイズを設定
    lv_disp_draw_buf_init(&draw_buf, buf, NULL, 320 * 10); // 解像度に基づいてバッファサイズを設定  
    // LVGLのディスプレイドライバー設定 

    lv_disp_drv_init(&disp_drv);
    disp_drv.hor_res = 480; // ディスプレイの解像度を設定
    disp_drv.ver_res = 320;
    disp_drv.flush_cb = my_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    lv_disp_drv_register(&disp_drv);


    #if 1
    // タッチパッド入力デバイスを初期化して登録
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = my_touchpad_read;
    lv_indev_drv_register(&indev_drv);
    #endif


    static lv_style_t style1;
    lv_style_init(&style1);
    lv_style_set_text_font(&style1, &jpFont04);
  
    static lv_style_t style2;
    lv_style_init(&style2);
    lv_style_set_text_font(&style2, &lv_font_montserrat_48);


    // 時刻表示用ラベルの作成
    time_label = lv_label_create(lv_scr_act());
    lv_obj_add_style(time_label, &style2, 0); // スタイルを適用
    lv_label_set_text(time_label, "00:00");
    lv_obj_align(time_label, LV_ALIGN_CENTER, 0, 0);  
   
    // wifi状態表示用ラベルの作成
    wifiStatus_label = lv_label_create(lv_scr_act());
    lv_obj_add_style(wifiStatus_label, &style1, 0); // スタイルを適用
    lv_label_set_text(wifiStatus_label, "WiFi接続中...");
    lv_obj_align(wifiStatus_label, LV_ALIGN_CENTER, 0, 0);

    // ボタンの作成
    settings_btn = lv_btn_create(lv_scr_act());
    lv_obj_add_style(settings_btn, &style1, 0); // スタイルを適用
    lv_obj_set_size(settings_btn, 100, 50); // ボタンのサイズ設定
    lv_obj_align(settings_btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10); // 画面の右下隅に配置
    lv_obj_add_event_cb(settings_btn, btn_event_setting_cb, LV_EVENT_CLICKED , NULL); // ボタンアクションの新しい設定方法

    // ボタンにラベルを追加
    lv_obj_t *settings_label = lv_label_create(settings_btn);
    lv_label_set_text(settings_label, "設定");

    // ... その他の初期化コード ...
    Serial.println("clock_setup end");
}



// NTP更新用のタスク
void ntpUpdateTask(void *pvParameters) {
  Serial.println("タスク_ntpUpdateTask_start");

  for (;;) {
    Serial.println("test_ntpUpdateTask");
    vTaskDelay(1000); 
    #if 1
    if (WiFi.status() == WL_CONNECTED) {
      timeClient.update();
      String currentTime = timeClient.getFormattedTime();
      if (time_label != NULL) {
        lv_label_set_text(time_label, currentTime.c_str());
      }
      if (wifiStatus_label != NULL)
      {
        lv_label_set_text(wifiStatus_label, " ");
      }
      
    } else {
      Serial.println("WiFiが接続されていません");
      // WiFiに接続できていない場合は警告メッセージを表示
      // 使用前にNULLでないことをチェック
      if (time_label != NULL) {
        lv_label_set_text(wifiStatus_label, "NTP接続不可 確認してください!");
      }
    }
    //vTaskDelay(3600000 / portTICK_PERIOD_MS); // 1時間ごと
    #endif
  }
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Code to reproduce 2024/1/23

When transitioning from the time display screen to the numeric keypad screen,

If you add code to delete the label and button using the lv_obj_del function, it will start again.

static void btn_event_setting_cb(lv_event_t *event) {
    
---------------------(省略)----------------------------------------------------------

        lv_obj_del(time_label); // ボタンオブジェクトを削除
        lv_obj_del(wifiStatus_label); // ボタンオブジェクトを削除
        lv_obj_del(settings_btn); // ボタンオブジェクトを削除
        tenkey_setup();
    }
}

This is the monitor output code when restarting.

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
clock_setup Start
clock_setup end
タスク_ntpUpdateTask_start
test_ntpUpdateTask
WiFiが接続されていません
test_ntpUpdateTask
test_ntpUpdateTask
test_ntpUpdateTask
test_ntpUpdateTask
test_ntpUpdateTask
設定ボタン_イベントハンドラ呼び出し
設定ボタンがクリックされました
tenkey_setup Start
tenkey_setup End
Guru Meditation Error: Core  0 panic'ed (LoadStoreError). Exception was unhandled.

Core  0 register dump:
PC      : 0x40174ec2  PS      : 0x00060f30  A0      : 0x800d5d77  A1      : 0x3ffdce70
A2      : 0x00000000  A3      : 0x3ffdceac  A4      : 0x00000002  A5      : 0x00000001  
A6      : 0x00000008  A7      : 0x3ffdceac  A8      : 0x400d9f98  A9      : 0x3ffdce00
A10     : 0x3ffdce6c  A11     : 0x3ffdceac  A12     : 0x00000008  A13     : 0x3ffdceb5  
A14     : 0x00000000  A15     : 0xff000000  SAR     : 0x0000000a  EXCCAUSE: 0x00000003
EXCVADDR: 0x400d9fae  LBEG    : 0x400891a0  LEND    : 0x400891aa  LCOUNT  : 0x00000000  


Backtrace: 0x40174ebf:0x3ffdce70 0x400d5d74:0x3ffdce90 0x400e0001:0x3ffdcec0 0x400d2023:0x3ffdcee0




ELF file SHA256: 5f6d8e708c9dd73b

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
clock_setup Start
clock_setup end
タスク_ntpUpdateTask_start
test_ntpUpdateTask
WiFiが接続されていません
test_ntpUpdateTask
WiFiが接続されていません
test_ntpUpdateTask
test_ntpUpdateTask

From this monitor output
Serial.println(“tenkey_setup End”);
after this code

Guru Meditation Error: Core 0 panic’ed (LoadStoreError). Exception was unhandled.

It looks like you’re getting this error.


void tenkey_setup() {
    Serial.begin(115200); // シリアル通信の初期化
    Serial.println("tenkey_setup Start");

---------------(省略)-----------------------------------------
 
    Serial.println("tenkey_setup End");
}

what code you use to switch between screens ?