4 Chart animation

4.1 experimental goals

In this lesson, you will learn how to animate a chart.

The reference code path for this experiment is :CanMV\04-GUI\chart_anime.py

 

4.2 experimental procedure

The factory firmware of the module has been integrated with the lvgl graphical library. If you have downloaded other firmware, please burn it back to the factory firmware before experimenting.

  1. Import the relevant libraries and initialize the lvgl, register the display interface, and register the input interface.

  2. Create a new animation class, Anim.

  1. Create a new animated chart class, AnimatedChart.

  1. Configure the parameters for the animated chart.

  1. Create a new slider to change the speed at which the animation changes.

  1. Load the lvgl project object. Since the images of the lvgl need to be updated in real time, the tasks of the lvgl need to be refreshes every 5 milliseconds.

 

4.3 experimental results

Connect the K210 module to the computer through the microUSB data cable, CanMV IDE click the connect button, after the connection is completed click the Run button to run the routine code. You can also download the code as main.py and run it in the K210 module.

You can see that a chart is displayed in the middle of the LCD screen, and the curve in the chart will change. You can change the speed of the curve in the chart by sliding the slider on the right.

image-20230214180124071

 

4.4 experiment summary

Animating a chart is a complex task, so you'll need to create two new animation-related classes to store the corresponding parameter information. The slider changes the rate at which the animation takes place. It doesn't take effect until the slider has finished animating, that is, until all the curves have reached their lowest point.