Elegoo 2.8TFT LCD e dati in tempo reale

Ciao a tutti, chiedo gentilmente il vostro aiuto, anticipo sono una frana, ho un Elegoo 2.8TFT LCD montato sopra una scheda Arduino Mega, fin qui tutto semplice, ho caricato uno sketch che mi piaceva e volevo adattarlo alle mie esigenze così intanto forse imparavo, quando accendo il tutto si avvia la prima pagina (F0) qui io sono riuscito a personalizzare un po il tutto ma non riesco ad avere i dati letti in tempo reale, per esempio alto a sx dovrei leggere un dato analogico che mi arriva dal pin A11 ma vedo un bel 0, se premo un altro tasto (il display è touch e ha quattro tasti) allora leggo il dato ma rimane un dato fisso non ho una lettura costante, cosa sbaglio e cosa devo fare Grazie
Ho caricato in parte lo sketch quello completo l'ho allegato perché non me lo lascia caricare
Grazie ancora

#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
 
#include <Elegoo_GFX.h>    // Core graphics library: https://github.com/Erutan409/Elegoo_GFX
#include <Elegoo_TFTLCD.h> // Hardware-specific library: https://github.com/Erutan409/Elegoo_TFTLCD
#include <TouchScreen.h>  // https://github.com/Erutan409/Elegoo_Touchscreen

//#if defined(__SAM3X8E__)
//#undef __FlashStringHelper::F(string_literal)
//#define F(string_literal) string_literal
//#endif

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7

// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 22
//   D1 connects to digital pin 23
//   D2 connects to digital pin 24
//   D3 connects to digital pin 25
//   D4 connects to digital pin 26
//   D5 connects to digital pin 27
//   D6 connects to digital pin 28
//   D7 connects to digital pin 29


#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

//Touch For New ILI9341 TP
#define TS_MINX 120
#define TS_MAXX 900

#define TS_MINY 70
#define TS_MAXY 920

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define BLACK       0x0000      /*   0,   0,   0 */
#define NAVY        0x000F      /*   0,   0, 128 */
#define DARKGREEN   0x03E0      /*   0, 128,   0 */
#define DARKCYAN    0x03EF      /*   0, 128, 128 */
#define MAROON      0x7800      /* 128,   0,   0 */
#define PURPLE      0x780F      /* 128,   0, 128 */
#define OLIVE       0x7BE0      /* 128, 128,   0 */
#define LIGHTGREY   0xC618      /* 192, 192, 192 */
#define DARKGREY    0x7BEF      /* 128, 128, 128 */
#define BLUE        0x001F      /*   0,   0, 255 */
#define GREEN       0x07E0      /*   0, 255,   0 */
#define CYAN        0x07FF      /*   0, 255, 255 */
#define RED         0xF800      /* 255,   0,   0 */
#define MAGENTA     0xF81F      /* 255,   0, 255 */
#define YELLOW      0xFFE0      /* 255, 255,   0 */
#define WHITE       0xFFFF      /* 255, 255, 255 */
#define ORANGE      0xFD20      /* 255, 165,   0 */
#define GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define PINK        0xF81F
#define GRAY        0xDEFB

Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define PENRADIUS 3


int fbutton_id = 0;
int clickcounter = 0;
int screen_id = 0;
int value_bar = 0;
boolean runstop = true;
unsigned long startMillis;           //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 5000;   //the value is a number of milliseconds


#define buton2 22
//unsigned long startTime;
//unsigned long elapsedTime;
boolean isAcquisire = false, isStopped = false;
unsigned long oldmillis = 0;
bool avviato, s, spenta;
unsigned long intervallo = 0;
boolean picco = false;
unsigned long prevmillis2 = 0;


const byte pinBatt=A12;
float Batt;
byte valore;

unsigned int sample; // , Vmin = 614;// Vmin del pacco 3S

float Voltage = 0.0;
float Power = 0.0;
float Current = 0.0;
float ampsH = 0.0;  // ampere ora
float t;

float resistance1 = 20000.0; //20kohm
float resistance2 = 68000.0; //68kohm
float multiplier = 0.1875F; /* ADS1115  @ +/- 6.144V gain (16-bit results) */

void setup(void) {
  Serial.begin(9600);
  //Serial.println(F("Paint!"));
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Timer,t (ore),ADC,Volt,Ampere,Watt,Capacità Ah");
  delay(5000);


  tft.reset();

  uint16_t identifier = tft.readID();
  
  {
    identifier = 0x9341;  
  }

  tft.begin(identifier);
  tft.setRotation(1);
  screen_main();

 //ADS1015
  ads.setGain(GAIN_TWOTHIRDS);
  ads.begin(); 
  pinMode(buton2, INPUT_PULLUP);       
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop()
{
MeasurePower();
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = (tft.height() - map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));


    if (screen_id == 0) {//Get touch on Main-Screen

      if (p.x > 280 && p.y > 180) {
        fbutton_id = 1;
        clickcounter++;
        screen_f1();
      }

      if (p.x > 280 && p.y < 180 && p.y > 120) {
        fbutton_id = 2;
        clickcounter++;


        
        screen_f2();
      }

      if (p.x > 280  && p.y < 120 && p.y > 60) {
        fbutton_id = 3;
        clickcounter++;
        screen_f3();

        
      }


    } else if (screen_id == 1) { //F1 screen action
      if (p.x > 200 && p.x < 250 && p.y < 220 && p.y > 160) {
        clickcounter++;
        screen_main();
        //Action on F1-Screen yes
      }

      if (p.x > 200 && p.x < 250  && p.y < 75 && p.y > 20) {
        clickcounter++;
        screen_main();
        //Action on F1-Screen no
      }
    }

    else if (screen_id == 2) { //F2 screen action
      if (p.x > 200 && p.x < 250 && p.y < 150 && p.y > 95) {
        clickcounter++;
        screen_main();
        //Action on F2-Screen ok
      }
    }

    else if (screen_id == 3) { //F3 screen action
      if (p.x > 200 && p.x < 250 && p.y < 155 && p.y > 95) {
        clickcounter++;
        screen_main();
        //Action on F3-Screen ok
      }
      if (p.x > 130 && p.x < 170 && p.y < 225 && p.y > 13) {
        value_bar = (216 - p.y + 8) / 2.1;
        tft.fillRect(15 + value_bar * 2.9, 100, 290 - value_bar * 2.9, 30, WHITE);
        tft.fillRect(15, 100, value_bar * 2.9, 30, RED);
        tft.fillRect(120, 40, 120, 40 , BLACK);
        tft.setCursor(125, 50);
        tft.setTextColor(WHITE);
        tft.setTextSize(3);
        tft.print(value_bar);
        tft.println("%");
        //Action if value-bar changed
      }
    }
  
   if (p.x > 280  && p.y <= 60 && p.y >= 0) {//F4 screen action
      fbutton_id = 4;
      clickcounter++;
      if (runstop == true) {
        runstop = false;
      } else {
        runstop = true;
      }
      screen_main();
    }
  }

power_analyser_ACS712_Eleego.ino (13 KB)

speravo in qualche aiuto sinceramente

Alle 6.24 del mattino? Sei molto ottimista direi....

Non mi è ben chiaro quale sia il tuo attuale livello di comprensione dello sketch che hai postato, ma a naso direi beginner, perché come hai potuto constatare non basta cambiare qualche stringa qui e la.

Il codice che hai postato esegue l'aggiornamento del display come CONSEGUENZA della pressione sul touch, tu invece vuoi che questo aggiornamento sia CONSEGUENZA della variazione di una variabile o magari continuo (approccio che personalmente amo poco). Tutte le istruzioni infatti sono eseguite a partire dai valori ritornati dal metodo getPoint() della libreria.
TSPoint p = ts.getPoint();

Come sempre, non si tratta di capire dove e come scrivere qualche istruzione, ma di definire COSA deve fare il tuo algoritmo. A quel punto inizi a familiarizzare con i metodi messi a disposizione dalla libreria e a scrivere il codice.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.