#include <lvgl.h>
#include <lvgl/src/lv_core/lv_obj.h>
#include <lvgl/src/lv_core/lv_disp.h>
#include <lvgl/src/lv_themes/lv_theme_material.h>
#include <lvgl/src/lv_widgets/lv_btn.h>
// LVGL display buffer
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10];
void setup() {
// Initialize LVGL
lv_init();
// Create a display buffer
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
// Create an LVGL display
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.flush_cb = [](lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) {
// Implement your display driver flush function here
// This function is called by LVGL to update the display
// Make sure to write the pixel data to your display hardware
};
disp_drv.buffer = &disp_buf;
lv_disp_drv_register(&disp_drv);
// Create a screen
lv_obj_t *scr = lv_disp_get_scr_act(NULL);
// Create a label
lv_obj_t *label = lv_label_create(scr, NULL);
lv_label_set_text(label, "Hello, LVGL!");
// Create a button
lv_obj_t *btn = lv_btn_create(scr, NULL);
lv_obj_set_pos(btn, 50, 50);
lv_obj_set_size(btn, 100, 40);
lv_obj_t *label_btn = lv_label_create(btn, NULL);
lv_label_set_text(label_btn, "Click me!");
// Set button click event
lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, btn_click_action);
}
void loop() {
// Handle LVGL tasks
lv_task_handler();
delay(5); // Adjust delay as needed
}
// Button click event handler
static void btn_click_action(lv_obj_t *btn, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
// Button clicked, implement your action here
// For example, toggle an LED, change the screen, etc.
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch