Skip to content

Commit

Permalink
Add helloworld example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jan 27, 2024
1 parent 3e2da9e commit 7cee618
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions examples/lv_helloworld/lv_helloworld.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @file lv_helloworld.ino
* @author Lewis He ([email protected])
* @license MIT
* @copyright Copyright (c) 2024 Shenzhen Xin Yuan Electronic Technology Co., Ltd
* @date 2024-01-27
*/

#include <LilyGo_RGBPanel.h>
#include <LV_Helper.h>

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);
}

















8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +32,6 @@ boards_dir = boards

[env:T-RGB]
lib_extra_dirs = ${PROJECT_DIR}
lib_ignore = lib_deps
platform = [email protected]
board = LilyGo-T-RGB
framework = arduino
Expand All @@ -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
Expand Down

0 comments on commit 7cee618

Please sign in to comment.