Let's try making some changes to the code in the main.cpp file. First, let's make the text "Hello, ESP32-S3!" larger. To do this, we'll need to create a new style and customize it by changing the font to one that supports the desired text size.
// Create and display label
lv_obj_t *label = lv_label_create(lv_scr_act());
// Create a style for text
static lv_style_t style;
lv_style_init(&style);
// Customize the style by setting the font
// Here lv_font_montserrat_42 is an example font
lv_style_set_text_font(&style, &lv_font_montserrat_42);
// Applying style to label
lv_obj_add_style(label, &style, 0);
lv_label_set_text(label, "Hello, ESP32-S3!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

Let's try adding animation.
To set up animation for LVGL interface elements (for example, for a label), you need to perform several steps:
- Create an animation with a start and end state (for example, changing position, size, or opacity).
- Specify the animation duration and other parameters, such as delay or repeat.
- Start the animation.
Example code for creating a simple animation:
// Function for position animation
static void anim_x_cb(void * var, int32_t v) {
lv_obj_set_x((lv_obj_t *)var, v);
}
void create_animation(lv_obj_t * label) {
// Create animation
lv_anim_t a;
lv_anim_init(&a);
// Setting animation parameters
lv_anim_set_var(&a, label); // Animated object
lv_anim_set_exec_cb(&a, anim_x_cb); // Callback for changing a property (e.g. position)
lv_anim_set_values(&a, 0, 100); // From initial position x=0 to x=100
lv_anim_set_time(&a, 1000); // Animation duration (1000 ms)
lv_anim_set_delay(&a, 500); // Delay before start (500 ms)
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); // Infinite repeat
// Let's start the animation
lv_anim_start(&a);
}
This example creates an animation that moves a label along the X axis from 0 to 100 pixels in 1 second, with a 500ms delay and looping infinitely.
Applying an animation to a label:
- Define your animation in a separate function (like the example above).
- Call this function after creating the label.
lv_label_set_text(label, "Hello, ESP32-S3!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
create_animation(label);
If we want to move the label along the Y axis, we simply change the line
lv_obj_set_x((lv_obj_t *)var, v);
as follows
lv_obj_set_y((lv_obj_t *)var, v);
Let's change the program so that it cyclically changes the text in the label field.
To do this, we'll create an array of words.
// Array of words to display
static const char *words[] = {
"Hello",
"World",
"This",
"Is",
"LVGL",
"On",
"ESP32"
};
static const int num_words = sizeof(words) / sizeof(words[0]);
Let's create the 'update_label_text' function. The 'update_label_text' function is responsible for updating the text displayed on a label widget in the LVGL GUI. This function is called periodically by a timer to cycle through a predefined list of words.
static void update_label_text(lv_timer_t * timer) {
static int word_index = 0;
lv_obj_t * label = (lv_obj_t *)timer->user_data;
// Update label text to the next word
lv_label_set_text(label, words[word_index]);
// Move to the next word index, wrap around if necessary
word_index = (word_index + 1) % num_words;
}
Now let's create the 'create_label_with_timer' function. This function creates a label widget on the LVGL screen and sets up a timer to periodically update its text. This provides a dynamic text display that cycles through a list of words.
void create_label_with_timer(lv_obj_t * parent) {
// Create label
lv_obj_t * label = lv_label_create(parent);
// Create style for text
static lv_style_t style;
lv_style_init(&style);
// Set font style
lv_style_set_text_font(&style, &lv_font_montserrat_48);
// Apply style to label
lv_obj_add_style(label, &style, 0);
// Set initial text
lv_label_set_text(label, words[0]);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
// Create timer to update text every 1 second
lv_timer_t * timer = lv_timer_create(update_label_text, 1000, label);
}
Let's replace this section of code in the 'app_main' function
// Create and display label
lv_obj_t *label = lv_label_create(lv_scr_act());
// Create a style for text
static lv_style_t style;
lv_style_init(&style);
// Customize the style by setting the font
// Here lv_font_montserrat_42 is an example font
lv_style_set_text_font(&style, &lv_font_montserrat_42);
// Applying style to label
lv_obj_add_style(label, &style, 0);
lv_label_set_text(label, "Hello, ESP32-S3!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
with
//lv_obj_t *label = lv_label_create(lv_scr_act());
create_label_with_timer(lv_scr_act());
The result:

Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Cool!! Great update!! I'm literally more excited about this project than I have been about anything in awhile. RSVP changed my life. My current favorite RSVP implementation is sprint reader on Chrome and it stinks that it's exclusively on Chrome, but might be worth checking out if you're interested in (my opinion) the best current iteration of RSVP. I know it's open source but my code knowledge is lacking. https://chromewebstore.google.com/detail/sprint-reader-speed-readi/kejhpkmainjkpiablnfdppneidnkhdif?hl=en https://github.com/anthonynosek/sprint-reader-chrome
Are you sure? yes | no