Description
I am trying to implement a transition on some some text to change color. More generally, I am trying to understand how transitions work. I am adapting the code from this style example as my starting place: Styles — LVGL documentation
As well as this on sending events:
https://docs.lvgl.io/9.2/overview/event.html#custom-events
I have a sense I am approaching this incorrectly. Maybe I need a call back function?
What MCU/Processor/Board and compiler are you using?
Arduino Giga with Arduino IDE 2.3.4
What LVGL version are you using?
9.2.2
What do you want to achieve?
I want my code to transition from one color to another, similar to the button transition example in the docs.
What have you tried so far?
Meshing some basic example code from the docs.
Code to reproduce
I know this is not the simulator code. Trying to understand how the simulator works in practice has been a bit of challenge.
If this is not acceptable, I understand. And thoughts would be highly appreciated. All the best.
#include "Arduino_BMI270_BMM150.h"
#include "Arduino_H7_Video.h"
#include "lvgl.h"
#include "lv_conf.h"
Arduino_H7_Video Display(800, 480, GigaDisplayShield); /* Arduino_H7_Video Display(1024, 768, USBCVideo); */
BoschSensorClass imu(Wire1);
// Custom Event
uint32_t SHAKE_EVENT;
// Text
lv_obj_t * label;
void setup() {
Serial.begin(9600);
Display.begin();
imu.begin();
// Register Custom Even
SHAKE_EVENT = lv_event_register_id();
/******* Transitions ************************************/
// Properties that will change during a transition
static const lv_style_prop_t trans_props[] = {
LV_STYLE_TEXT_COLOR,
0, /*End marker*/
};
// Show Fortune Transition Description
static lv_style_transition_dsc_t trans_show_fortune;
lv_style_transition_dsc_init(&trans_show_fortune, trans_props, lv_anim_path_ease_out, 500, 100, NULL);
// Get Fortune Transition Description
static lv_style_transition_dsc_t trans_get_fortune;
lv_style_transition_dsc_init(&trans_get_fortune, trans_props, lv_anim_path_ease_out, 1000, 0, NULL);
/******** Styles **********************************/
// Default Style
static lv_style_t style_show_fortune;
lv_style_init(&style_show_fortune);
lv_style_set_text_font(&style_show_fortune, &lv_font_montserrat_42);
lv_style_set_text_color(&style_show_fortune, lv_color_hex(0x2ecc71));
lv_style_set_transition(&style_show_fortune, &trans_show_fortune);
// Shake Style
static lv_style_t style_get_fortune;
lv_style_init(&style_get_fortune);
lv_style_set_text_color(&style_get_fortune, lv_color_hex(0xEF7422));
lv_style_set_transition(&style_get_fortune, &trans_get_fortune);
/* Objects **********************************/
/*Create an object with the new style*/
label = lv_label_create(lv_screen_active());
lv_obj_center(label);
lv_label_set_text(label, "Drag me!");
lv_obj_add_style(label, &style_show_fortune, 0);
lv_obj_add_style(label, &style_get_fortune, SHAKE_EVENT);
}
void loop() {
float x, y, z;
static int count = 0;
if (imu.accelerationAvailable()) {
imu.readAcceleration(x, y, z);
if (z < 0.8 && z > -0.8) {
Serial.println(count++);
lv_obj_send_event(label, LV_EVENT_PRESSED, NULL);
}
}
lv_timer_handler();
}