I have built Home Security sensor application based on SMART HOME Tutorial. Reconfigured to use ESP NOW Point to Point between sensors and monitor EP32 driving OLED. Very stable system.
Based on Learn LGVL, I modified the sketch to use ESP NOW Many to One to display on CYD.
As I code by example I need help or pointers with 3 items.
1) How to get the LVGL GUI to set the color of LED based on value set with decoded loop array. Serial Monitor shows loop variable’s state of the sensors from both of my ESP32.
2) How to add % symbol to Humidity value?
3) How to show only one decimal point.
Hi.
To control the color is the same as controlling any other RGB LED:
The RGB LED is connected to the following pins: red (GPIO 4), green (GPIO 16), and blue (GPIO 17).
They work with inverted logic.
You just need to concatenate the % sign with the humidity value converted to a string.
Regards,
Sara
I think my question was not clear. The LVGL main gui function will not accept variables defined in the loop. When I enter a condition (IF) the variable does not resister in to the gui. So my question is how do I input my variable’s state into the LVGL main GUI? My desire is to have my garage door status control the color of an LVGL LED.
Hi.
You can call functions to change the appearance of LVGL objects in the loop().
For example, this function that sets the background color of objects.
lv_obj_set_style_bg_color()
Just make sure the LVGL object you want to control is declared outside a function so that it can be accessed throughout all the code.
You can see an example of that in unit 6.2 (but we update text labels instead of colors)—take a look at the loop() function of that project.
Regards,
Sara
Sara,
I greatly appreciate your assistance, however all my attempts have failed to compile, so I do not understand how to properly code for the desired results. Learn LVGL course has provided me with an operational system to display my garage sensors and my standby generator enclose temperatures. My request for example code to control the color of a LVGL LED is still open.
What exactly do you mean by an LVGL LED?
Are you referring to a button that changes color according to the value of a variable?
The LVGL library shows a widget for LED. Using this example as guidance I placed 3 LED widgets on Tab1 in the lvgl-main_gui.
My goal is to have these LED Widgets set the LED color based on condition of variables in the loop as with my code Boolean value for “bigDoorStatus”. The lvgl main gui function creates the LED widget, how to modify it is where I need help. Seem as a void function for each led widget for the two colors required and code in the loop to call the function is what I’ve tried and completely failed to compile. I apologize for not having a better understanding of functions and function calls coding but point out Random Nerds courses and web pages have provided the experience and training for what I have accomplish.
The LVGL library shows a widget for LED. Using this example as guidance I placed 3 LED widgets on Tab1 in the lvgl-main_gui.
My goal is to have these LED Widgets set the LED color based on condition of variables in the loop as with my code Boolean value for “bigDoorStatus”. The lvgl main gui function creates the LED widget, how to modify it is where I need help. Seem as a void function for each led widget for the two colors required and code in the loop to call the function is what I’ve tried and completely failed to compile. I apologize for not having a better understanding of functions and function calls coding but point out Random Nerds courses and web pages have provided the experience and training for what I have accomplish.
Hi.
Please share the minimal code you have trying to implement this feature so that I can take a look.
Please share it using pastebin or github
Regards.
sara
/**** VARIABLES ****/
// Timers auxiliar variables
long now;//= millis();
long lastMeasure = 0;
bool smallDoorStatus;
bool bigDoorStatus;
bool DayNight;
bool smallDoorWarn;
bool bigDoorWarn;
bool auralAlert;
float genProbe1;
float genProbe2;
float garTemp;
float garHumid;
int genVolts;
int outSideLite;
// Set the color of Big Door LED Green is normal, Red unsafe
//error: ‘bigDoorLed’ was not declared in this scope lv_led_set_color(bigDoorLed(),
// “bigDoorLed” is name of function defining my Big Door LED
//my function to set color on LVGL LED
void bigDoorGreen(){
bool bigDoorLed;
lv_led_set_color(bigDoorLed, lv_palette_main(LV_PALETTE_GREEN));
}
void lv_create_main_gui(void) {
// Create a Tab view object
lv_obj_t * tabview;
tabview = lv_tabview_create(lv_screen_active());
lv_tabview_set_tab_bar_size(tabview, 40);
// Add 3 tabs (the tabs are page (lv_page) and can be scrolled
lv_obj_t * tab1 = lv_tabview_add_tab(tabview, “GARAGE”);
lv_obj_t * tab2 = lv_tabview_add_tab(tabview, “GENERATOR”);
//Create a LED for Big Door Status
lv_obj_t * bigDoorLed = lv_led_create(tab1);{
//lv_obj_t * led1 = lv_led_create(lv_screen_active());
//lv_led_set_color(bigDoorLed, lv_palette_main(LV_PALETTE_GREEN));
lv_obj_align(bigDoorLed, LV_ALIGN_CENTER, 20, -30);
}
//in loop()
// Acess the variables for each board
int board1ac = boardsStruct[0].ac;//null ac volts from Geneator sensor
outSideLite = boardsStruct[0].f;//ambient ADC Value outside lighting
garTemp = boardsStruct[0].t1;//garage temp
garHumid = boardsStruct[0].t2;//garage humidity
smallDoorStatus = boardsStruct[0].a;//small door status
bigDoorStatus = boardsStruct[0].b;//big door status
DayNight = boardsStruct[0].c;//day/night board1, null board 2
smallDoorWarn = boardsStruct[0].d;//warn status board1, null board2
bigDoorWarn = boardsStruct[0].e;// warn status bigDoor board1, null board2
genVolts = boardsStruct[1].ac;//generator ac voltage value
int board2f = boardsStruct[1].f;//null board2
genProbe1 = boardsStruct[1].t1;//generator temp probe1 (internal)
genProbe2 = boardsStruct[1].t2;//generator temp probe2 (outside)
bool board2a = boardsStruct[1].a;//null bd2 (not assigned)
bool board2b = boardsStruct[1].b;//null board2
bool board2c = boardsStruct[1].c;//null board2
bool board2d = boardsStruct[1].b;//null board2
bool board2e = boardsStruct[1].c;//null board2
if(bigDoorSttus == 1){
bigDoorGreen();
}
Hi.
If you take a look at the documentation, you can see that the lc_led_set_color() function accepts the following as arguments:
void lv_led_set_color(lv_obj_t *led, lv_color_t color)
Parameters :
- led — pointer to a LED object
- color — the color of the LED
The first argument is a pointer to an LED object. You’re passing a boolean variable.
https://docs.lvgl.io/9.2/API/widgets/led/lv_led.html#_CPPv416lv_led_set_colorP8lv_obj_t10lv_color_t
To create an LED object: https://docs.lvgl.io/9.2/API/widgets/led/lv_led.html#_CPPv413lv_led_createP8lv_obj_t
It will be easier if you try just to create a basic example with one LED and then once you have it working, apply it to your current project.
Regards,
Sara