I made this code to graph outputs from 3 pins. Is there any way to label this graph?
#include <Arduino_GigaDisplay.h>
#include <lvgl.h>
#include "Arduino_H7_Video.h"
#include "ArduinoGraphics.h"
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
#define OP1_PIN A0
#define OP2_PIN A1
#define OP3_PIN A2
static lv_obj_t * chart;
static lv_chart_series_t * ser1;
static lv_chart_series_t * ser2;
static lv_chart_series_t * ser3;
unsigned long previousDataPointMillis = 0;
const long dataPointInterval = 1000;
unsigned long chartStartTime = 0;
const unsigned long chartClearInterval = 60000;
void setup() {
Serial.begin(115200);
Display.begin();
chart = lv_chart_create(lv_scr_act());
lv_obj_set_size(chart, Display.width(), Display.height());
lv_obj_align(chart, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 1023);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, 0, 60);
lv_chart_set_point_count(chart, 61);
// --- Add the Three Lines (Data Series) ---
ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_PRIMARY_Y);
ser3 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
// Record the start time
chartStartTime = millis();
}
void loop() {
unsigned long currentMillis = millis();
// --- Add a new data point every second ---
if (currentMillis - previousDataPointMillis >= dataPointInterval) {
previousDataPointMillis = currentMillis;
// Read the analog values
int op1Value = analogRead(OP1_PIN);
int op2Value = analogRead(OP2_PIN);
int op3Value = analogRead(OP3_PIN);
// Print values to Serial Monitor for debugging
Serial.print("OP1: ");
Serial.print(op1Value);
Serial.print(", OP2: ");
Serial.print(op2Value);
Serial.print(", PM 2.5: ");
Serial.println(op3Value);
// Add the new values to the chart's data series
lv_chart_set_next_value(chart, ser1, op1Value);
lv_chart_set_next_value(chart, ser2, op2Value);
lv_chart_set_next_value(chart, ser3, op3Value);
}
// LVGL's internal handler. This needs to be called in the loop.
lv_timer_handler();
delay(500); // A small delay is good practice
}