Lv_meter examples, change indicator/needle value/position

Hello

The lv_meter examples animates the indicator value automatically (with some anim functions).
But how can I set the position/value of the indicator/needle manually?

lv_meter_set_indicator_value(ui.screen_meter_1, 0, count);

does not work…

Thank you

This works for me from an MQTT push

        lv_meter_set_indicator_value(DryerMeter, DryerIndic, level);

I think the problem is that 0 isnt an actual indicator…

yes, but how, where should this “DryerIndic” be defined?

Somewhere in a setup_scr_screen.c file I have the code see below.
Then in my main.c (loop) I try to set the position with the second code below - but this does not work…
I’m a beginner in C/C++, so it’s hard for me to define the right function, pointer, structure, class or whatever for this…

setup_scr_screen.c:

     //add scale screen_meter_1_scale_1
    lv_meter_scale_t *screen_meter_1_scale_1 = lv_meter_add_scale(ui->screen_meter_1);
    lv_meter_set_scale_ticks(ui->screen_meter_1, screen_meter_1_scale_1, 41, 2, 10, 
    lv_color_make(0xff, 0x00, 0x00));
    lv_meter_set_scale_major_ticks(ui->screen_meter_1, screen_meter_1_scale_1, 8, 5, 15, 
    lv_color_make(0xff, 0xff, 0x00), 10);
    lv_meter_set_scale_range(ui->screen_meter_1, screen_meter_1_scale_1, 0, 100, 300, 90);

    //add needle line for screen_meter_1_scale_1
    lv_meter_indicator_t *screen_meter_1_scale_1_ndline_0;
    screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(ui->screen_meter_1, 
    screen_meter_1_scale_1, 2, lv_color_make(0x00, 0x00, 0x00), -20);
    lv_meter_set_indicator_value(ui->screen_meter_1, screen_meter_1_scale_1_ndline_0, 30);

main.c:

    lv_meter_indicator_t *screen_meter_1_scale_1_ndline_0;
    //screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(guider_ui.screen_meter_1, 0, 2, lv_color_make(0x00, 0x00, 0x00), -20);
    lv_meter_set_indicator_value(guider_ui.screen_meter_1, screen_meter_1_scale_1_ndline_0, count);

lv_meter_scale_t *screen_meter_1_scale_1
and
lv_meter_indicator_t *screen_meter_1_scale_1_ndline_0

need to be global variables (in your h file)
Then you can call the update function with them.
screen_meter_1_scale_1 = lv_meter_add_scale(ui->screen_meter_1);
screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(ui->screen_meter_1, …

In your c files you dont need to declare them just use them as

Ok thank you, the needle moves now, with code below - but the previous drawn needle is not deleted? How to solve this? See picture below.

global in main.c:

lv_meter_indicator_t *screen_meter_1_scale_1_ndline_0;
lv_meter_scale_t *screen_meter_1_scale_1;

loop:

    screen_meter_1_scale_1 = lv_meter_add_scale(guider_ui.screen_meter_1);
	  screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(guider_ui.screen_meter_1, screen_meter_1_scale_1, 2, lv_color_make(0x00, 0x00, 0x00), -20);
	  lv_meter_set_indicator_value(guider_ui.screen_meter_1, screen_meter_1_scale_1_ndline_0, count);

I dont think you want this in the loop:

    screen_meter_1_scale_1 = lv_meter_add_scale(guider_ui.screen_meter_1);
	  screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(guider_ui.screen_meter_1, screen_meter_1_scale_1, 2, lv_color_make(0x00, 0x00, 0x00), -20);

As you are creating new needles on each loop. You want it in your initialization function.

Thank you very much. That did the job :slight_smile:

still one little strange thing, see picture below, this small black lines does not disappear:

image

Oh, thats really strange.

Do you have anything meter related other than this in your loop?

lv_meter_set_indicator_value(guider_ui.screen_meter_1, screen_meter_1_scale_1_ndline_0, count);

Strange. No other meter. It must be related to the three line code below.
If I comment out //screen_meter_1_scale_1 = lv_meter_add_scale(guider_ui.screen_meter_1);
these additional black ticks disappears, but of course also the needle…

at Init:

  screen_meter_1_scale_1 = lv_meter_add_scale(guider_ui.screen_meter_1);
  screen_meter_1_scale_1_ndline_0 = lv_meter_add_needle_line(guider_ui.screen_meter_1, screen_meter_1_scale_1, 2, lv_color_make(0x00, 0xFF, 0x00), -20);

in loop:
lv_meter_set_indicator_value(guider_ui.screen_meter_1, screen_meter_1_scale_1_ndline_0, count);