Ciao a tutti, come da titolo volevo visualizzare data e ora su uno schermo tft lcd. ho scritto il programma e penso ci siano degli errori abbastanza gravi
in alcuni punti… (Non ho ancora capito molto bene la libreria dello schermo). Pensavo di visualizzare ora e minuti al centro e i secondi al centro sotto le ore e i minuti e nell’angolo in basso a destra la temperatura. Una volta caricato il programma il risultato è abbastanza strano.
#include <TFT.h>
#include <SPI.h>
#define cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(cs, dc, rst);
char temperaturaPrintout[4];
char orabo[2];
char mibo[2];
char sebo[2];
int tempcels;
int ora=0, se=0, mi=0;
void setup() {
TFTscreen.begin();
TFTscreen.background(0, 0, 0);
TFTscreen.stroke(255,255,255);
TFTscreen.setTextSize(2);
TFTscreen.text("C",145,105);
}
void loop() {
tempcels=((analogRead(1)/1024.0)*5.0-0.5)*100; //Faccio il calcolo per convertire il valore letto dal pin analogico in gradi C
String temperatura = String(tempcels);
temperatura.toCharArray(temperaturaPrintout, 4);
//*****************
String oraschermo=String(ora);
oraschermo.toCharArray(orabo,2);
String mischermo=String(mi);
mischermo.toCharArray(mibo,2);
String seschermo=String(se);
seschermo.toCharArray(sebo,2);
//***************** //Visualizzo ora, minuti e secondi
TFTscreen.setTextSize(2);
TFTscreen.stroke(255,255,255);
TFTscreen.text(temperaturaPrintout, 120, 105);
TFTscreen.setTextSize(5);
TFTscreen.stroke(255,255,255);
if(ora<10){
TFTscreen.text("0",15,45);
TFTscreen.text(orabo,50,45);
}
else
TFTscreen.text(orabo,15,45);
TFTscreen.text(":",71,45);
if(mi<10){
TFTscreen.text("0",96,45);
TFTscreen.text(mibo,130,45);
}
else
TFTscreen.text(mibo,96,45);
TFTscreen.setTextSize(2);
if(se<10){
TFTscreen.text("0",65,85);
TFTscreen.text(sebo,83,85);
}
else{
TFTscreen.stroke(255,255,255);
TFTscreen.text(sebo,65,85);
}
delay(1000);
TFTscreen.setTextSize(2);
TFTscreen.stroke(0,0,0);
TFTscreen.text(temperaturaPrintout, 120, 105);
TFTscreen.setTextSize(5);
if(ora<10){ //Ripulisco lo schermo (PARTE CHE RITENGO SBAGLIATA)
TFTscreen.text("0",15,45);
TFTscreen.text(orabo,50,45);
}
else
TFTscreen.text(orabo,15,45);
TFTscreen.text(":",71,45);
if(mi<10){
TFTscreen.text("0",96,45);
TFTscreen.text(mibo,130,45);
}
else
TFTscreen.text(mibo,96,45);
if(se<10){
TFTscreen.text("0",65,85);
TFTscreen.text(sebo,83,85);
}
else
TFTscreen.text(sebo,65,85);
if(se>=59){ //Aumento ore minuti e secondi
mi++;
se=0;
}
if(mi>=59){
ora++;
mi=0;
}
se++;
}
. Teoricamente l’orologio non è nemmeno preciso, ma per il momento non mi interessa. Per impostare ora minuti e secondi non ho problemi. Quello che non quadra è il fatto che il programma pesa 10000 bytes per alla fine non fare granché e ci sono parti che forse sono inutili… Il punto è che non voglio che lo schermo lampeggi quando cambia ora o minuto o secondo e che il tutto sia più leggero. Magari potreste correggermi degli errori…