Graphing on the V5 screen

Another demo, this time using lvgl in VEXcode from the project I had posted here a few months back.

(which now has prebuilt library included in the repo so you don’t need to build it).

graph_demo_2

Code uses the lvgl chart object.

Code
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      Sun Sep 15 2019                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "vex.h"
#include "v5lvgl.h"

using namespace vex;

void
create_chart(lv_obj_t * parent) {
  lv_obj_t * chart = lv_chart_create(parent, NULL);
  lv_chart_set_type(chart, LV_CHART_TYPE_POINT);
  lv_chart_set_point_count(chart, 460 );
  lv_obj_set_size(chart, 460, 220 );
  lv_obj_set_pos(chart, 10, 10);
  lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
  lv_chart_series_t * s1 = lv_chart_add_series(chart, LV_COLOR_WHITE);
  lv_chart_series_t * s2 = lv_chart_add_series(chart, LV_COLOR_RED);

  int x = 0;
  int t = 0;
  
  while(1) {
    lv_chart_set_next(chart, s1, sin( x / 180.0 * 3.141) * 40 + 50 );
    if(t == 0)
      lv_chart_set_next(chart, s2, cos( x / 180.0 * 3.141) * 20 + 50 );
    if( x++ == 360 )
      x = 0;
    t = 1 - t;
    this_thread::sleep_for(5);
  }
}

int demo() {
    create_chart(lv_scr_act());
    return(0);
}

int main() {
    v5_lv_init();
    demo();

    while(1) {
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}

Here’s the project with lvgl library included and the minor changes to the build system made (the compiler needs to know where the lvgl header files are and the library needed to be added for the linker).

lvglChartDemo.zip (463.3 KB)