acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_meter_1.py (1762B)

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