1#!//opt/bin/lv_micropython -i 2import utime as time 3import lvgl as lv 4import display_driver 5 6def set_value(indic, v): 7 meter.set_indicator_value(indic, v) 8 9# 10# A simple meter 11# 12meter = lv.meter(lv.scr_act()) 13meter.center() 14meter.set_size(200, 200) 15 16# Add a scale first 17scale = meter.add_scale() 18meter.set_scale_ticks(scale, 51, 2, 10, lv.palette_main(lv.PALETTE.GREY)) 19meter.set_scale_major_ticks(scale, 10, 4, 15, lv.color_black(), 10) 20 21indic = lv.meter_indicator_t() 22 23# Add a blue arc to the start 24indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.BLUE), 0) 25meter.set_indicator_start_value(indic, 0) 26meter.set_indicator_end_value(indic, 20) 27 28# Make the tick lines blue at the start of the scale 29indic = meter.add_scale_lines(scale, lv.palette_main(lv.PALETTE.BLUE), lv.palette_main(lv.PALETTE.BLUE), False, 0) 30meter.set_indicator_start_value(indic, 0) 31meter.set_indicator_end_value(indic, 20) 32 33# Add a red arc to the end 34indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.RED), 0) 35meter.set_indicator_start_value(indic, 80) 36meter.set_indicator_end_value(indic, 100) 37 38# Make the tick lines red at the end of the scale 39indic = meter.add_scale_lines(scale, lv.palette_main(lv.PALETTE.RED), lv.palette_main(lv.PALETTE.RED), False, 0) 40meter.set_indicator_start_value(indic, 80) 41meter.set_indicator_end_value(indic, 100) 42 43# Add a needle line indicator 44indic = meter.add_needle_line(scale, 4, lv.palette_main(lv.PALETTE.GREY), -10) 45 46# Create an animation to set the value 47a = lv.anim_t() 48a.init() 49a.set_var(indic) 50a.set_values(0, 100) 51a.set_time(2000) 52a.set_repeat_delay(100) 53a.set_playback_time(500) 54a.set_playback_delay(100) 55a.set_repeat_count(lv.ANIM_REPEAT.INFINITE) 56a.set_custom_exec_cb(lambda a,val: set_value(indic,val)) 57lv.anim_t.start(a) 58 59