From 7cee6187c26e5769d3a96b7776a2e7ca2c997359 Mon Sep 17 00:00:00 2001 From: lewis Date: Sat, 27 Jan 2024 19:42:54 +0800 Subject: [PATCH] Add helloworld example --- .github/workflows/arduino_ci.yml | 1 + .github/workflows/pio.yml | 1 + README.md | 1 + examples/lv_helloworld/lv_helloworld.ino | 85 ++++++++++++++++++++++++ platformio.ini | 8 +-- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 examples/lv_helloworld/lv_helloworld.ino diff --git a/.github/workflows/arduino_ci.yml b/.github/workflows/arduino_ci.yml index 1e5f8d5..9cd03e2 100644 --- a/.github/workflows/arduino_ci.yml +++ b/.github/workflows/arduino_ci.yml @@ -22,6 +22,7 @@ jobs: examples/BatteryVoltage/BatteryVoltage.ino, examples/lv_benchmark/lv_benchmark.ino, examples/lv_factory/lv_factory.ino, + examples/lv_helloworld/lv_helloworld.ino, examples/lv_gif/lv_gif.ino, examples/lv_images/lv_images.ino, examples/lv_music/lv_music.ino, diff --git a/.github/workflows/pio.yml b/.github/workflows/pio.yml index 42c74a7..ce233c6 100644 --- a/.github/workflows/pio.yml +++ b/.github/workflows/pio.yml @@ -21,6 +21,7 @@ jobs: examples/BatteryVoltage, examples/lv_benchmark, examples/lv_factory, + examples/lv_helloworld, examples/lv_gif, examples/lv_images, examples/lv_music, diff --git a/README.md b/README.md index 80b215b..cf4a6ed 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ examples/ ├── RGBPanel # lvgl test example ├── TFT_eSPI_Sprite # TFT_eSPI Sprite Example ├── Touchpad # Capacitive touch example +├── lv_helloworld # lvgl get started ├── lv_benchmark # lvgl benchmark example ├── lv_factory # factory example ├── lv_gif # lvgl gif decoding example diff --git a/examples/lv_helloworld/lv_helloworld.ino b/examples/lv_helloworld/lv_helloworld.ino new file mode 100644 index 0000000..1ea240b --- /dev/null +++ b/examples/lv_helloworld/lv_helloworld.ino @@ -0,0 +1,85 @@ +/** + * @file lv_helloworld.ino + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2024 Shenzhen Xin Yuan Electronic Technology Co., Ltd + * @date 2024-01-27 + */ + +#include +#include + +LilyGo_RGBPanel panel; + +static void btn_event_cb(lv_event_t *e) +{ + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t *btn = lv_event_get_target(e); + if (code == LV_EVENT_CLICKED) { + static uint8_t cnt = 0; + cnt++; + /*Get the first child of the button which is the label and change its text*/ + lv_obj_t *label = lv_obj_get_child(btn, 0); + lv_label_set_text_fmt(label, "Button: %d", cnt); + Serial.printf("Button :%d\n", cnt); + } +} + +void setup() +{ + Serial.begin(115200); + + + // Initialize T-RGB, if the initialization fails, false will be returned. + if (!panel.begin()) { + while (1) { + Serial.println("Error, failed to initialize T-RGB"); delay(1000); + } + } + + // Call lvgl initialization + beginLvglHelper(panel); + + + lv_obj_t *label = lv_label_create(lv_scr_act()); /*Add a label the current screen*/ + lv_label_set_text(label, "Hello World"); /*Set label text*/ + lv_obj_center(label); /*Set center alignment*/ + + + lv_obj_t *btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ + lv_obj_set_size(btn, 120, 50); /*Set its size*/ + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ + lv_obj_align_to(btn, label, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); /*Set the label to it and align it in the center below the label*/ + + lv_obj_t *btn_label = lv_label_create(btn); /*Add a label to the button*/ + lv_label_set_text(btn_label, "Button"); /*Set the labels text*/ + lv_obj_center(btn_label); + + // Turn on the backlight and set it to the highest value, ranging from 0 to 16 + panel.setBrightness(16); +} + + +void loop() +{ + // lvgl task processing should be placed in the loop function + lv_timer_handler(); + delay(2); +} + + + + + + + + + + + + + + + + + diff --git a/platformio.ini b/platformio.ini index 6f48376..3d0bee6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,13 +10,14 @@ [platformio] -src_dir = examples/lv_factory +; src_dir = examples/lv_factory ; src_dir = examples/lv_benchmark ; src_dir = examples/lv_music ; src_dir = examples/lv_images ; src_dir = examples/lv_gif ; src_dir = examples/lv_qrcode ; src_dir = examples/TFT_eSPI_Sprite +src_dir = examples/lv_helloworld ; src_dir = examples/RGBPanel ; src_dir = examples/Touchpad @@ -31,7 +32,6 @@ boards_dir = boards [env:T-RGB] lib_extra_dirs = ${PROJECT_DIR} -lib_ignore = lib_deps platform = espressif32@6.3.0 board = LilyGo-T-RGB framework = arduino @@ -48,10 +48,10 @@ build_flags = -DLV_CONF_SUPPRESS_DEFINE_CHECK ; Enable UARDUINO_USB_CDC_ON_BOOT will start printing and wait for terminal access during startup - ; -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_CDC_ON_BOOT=1 ; Enable UARDUINO_USB_CDC_ON_BOOT will turn off printing and will not block when using the battery - -UARDUINO_USB_CDC_ON_BOOT + ; -UARDUINO_USB_CDC_ON_BOOT -DCORE_DEBUG_LEVEL=0