vongomben / ITS-Bio-2023

Appunti sul corso di Telemetria Biomedica 2022-23 ITS
GNU Affero General Public License v3.0
0 stars 2 forks source link

Come visualizzare due grafici su uno schermo della Wio TErminal? #11

Open vongomben opened 1 year ago

vongomben commented 1 year ago

partiamo da qui

#include "seeed_line_chart.h"  //include the library

TFT_eSPI tft;

#define MAX_SIZE 30  // maximum size of data
doubles data;        // Initilising a doubles type to store data
doubles data2;       // Initilising a doubles type to store data

int brightness;
int brightness2;

void setup() {
  pinMode(WIO_LIGHT, INPUT);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_WHITE);
}

void loop() {
  brightness = analogRead(WIO_LIGHT);
  brightness2 = analogRead(WIO_LIGHT);

  if (data.size() > MAX_SIZE)  // keep the old line chart front
  {
    data.pop();  // this is used to remove the first read variable
  }

  data.push(brightness);  // read variables and store in data

  // Settings for the line graph title
  auto header = text(0, 0)
                  .value("Light Sensor Readings")
                  .align(center)
                  .valign(vcenter)
                  .width(tft.width())
                  .thickness(2);

  header.height(header.font_height(&tft) * 2);
  header.draw(&tft);  // Header height is the twice the height of the font

  // Settings for the line graph
  auto content = line_chart(20, header.height());  //(x,y) where the line graph begins
  content
    .height(tft.height() / 2 - (header.height() * 1.5) / 2)  // actual height of the line chart
    .width(tft.width() - content.x() * 2)                    // actual width of the line chart
    .based_on(0.0)                                           // Starting point of y-axis, must be a float
    .show_circle(true)                                       // drawing a cirle at each point, default is on.
    .value(data)                                             // passing through the data to line graph
    .max_size(MAX_SIZE)
    .color(TFT_RED)        // Setting the color for the line
    .backgroud(TFT_WHITE)  // Setting the color for the backgroud
    .draw(&tft);

  delay(200);

  // secondo grafico
  if (data2.size() > MAX_SIZE)  // keep the old line chart front
  {
    data2.pop();  // this is used to remove the first read variable
  }

  data2.push(brightness);  // read variables and store in data

  // Settings for the line graph title
  auto header2 = text(0, 0)
                  .value("Light Sensor Readings")
                  .align(center)
                  .valign(vcenter)
                  .width(tft.width())
                  .thickness(2);

  header.height(header2.font_height(&tft) * 2);
  header.draw(&tft);  // Header height is the twice the height of the font

  // Settings for the line graph
  auto content2 = line_chart(20, header2.height());  //(x,y) where the line graph begins
  content
    .height(tft.height() - (header2.height() * 1.5) / 2)  // actual height of the line chart
    .width(tft.width() - content.x() * 2)                    // actual width of the line chart
    .based_on(0.0)                                           // Starting point of y-axis, must be a float
    .show_circle(true)                                       // drawing a cirle at each point, default is on.
    .value(data)                                             // passing through the data to line graph
    .max_size(MAX_SIZE)
    .color(TFT_RED)        // Setting the color for the line
    .backgroud(TFT_WHITE)  // Setting the color for the backgroud
    .draw(&tft);

  delay(200);
}