salve a tutti, usando la libreria adafruit tftlcd , non riesco proprio a capire come fare a ""pulire "" il display
nel senso , in altre librerie per altri lcd trovo la funzione glcd.clear ma in questa libreria proprio non so come fare , c'e la funzione tft.reset ma lo inizializza e non mi va bene ..
sto cercando di fare visualizzare un orologio ma i secondi che scorrono si scrivono uno sull'altro
spero di aver allegato correttamente lo sketch
grazie in anticipo e buona pasqua
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define SET A5
#define PIU A6 // definisco pulsanti
#define MENO A7
char buffer[10];
unsigned long time=0;
unsigned long timeSet=0;
int setModeTime=2000;
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"Dom.", "Lun.", "Mar.", "Mer.", "Gio.", "Ven.", "Sab."};
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
pinMode( SET, INPUT );
pinMode( PIU, INPUT );
pinMode( MENO, INPUT );
uint16_t identifier = tft.readID();
identifier=0x9341;tft.begin(identifier);
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
delay(100);
}
void loop(void){
unsigned long start = micros();
if ( analogRead( SET ) < 1000) { time = millis(); }
DateTime now = RTC.now();
sprintf(buffer, "%02d/%02d/%d", now.day(), now.month(), now.year());
tft.setCursor(0,0);
tft.print( buffer );
char buffer[10] = "";
sprintf(buffer, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
tft.setCursor(0,50);
tft.print( buffer );
if (time > 0 && setModeTime < (millis() - time) ) { setMode( now ); }
tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
delay(100);
}
void setMode( DateTime now ) {
boolean setMode = true;
int setModeLevel = 0;
int _day = now.day();
int _month = now.month();
int _year = now.year();
int _hour = now.hour();
int _min = now.minute();
int _sec = now.second();
tft.fillScreen(CYAN);
tft.setTextColor(GREEN); tft.setTextSize(3);
tft.setCursor(0,0);
sprintf(buffer, "%s: %02d", "Giorno", _day);
delay( 1000 );
timeSet = millis();
while ( setMode ) {
if ( analogRead(SET) > 1000 || analogRead(PIU) > 1000 || analogRead(MENO) > 1000 ) { timeSet = millis(); }
tft.setCursor(0,0);
// Set Day
if ( setModeLevel == 0 ) {
if ( analogRead(PIU) > 1000 && _day < 31) { _day++; }
if ( analogRead(MENO) > 1000 && _day > 1) { _day--; }
sprintf(buffer, "%s: %02d", "Giorno", _day);
}
// Set Month
if ( setModeLevel == 1 ) {
if ( analogRead(PIU) > 1000 && _month < 12) { _month++; }
if ( analogRead(MENO) > 1000 && _month > 1) { _month--; }
sprintf(buffer, "%s: %02d", "Mese", _month);
}
// Set Year
if ( setModeLevel == 2 ) {
if ( analogRead(PIU) > 1000 && _year < 9999) { _year++; }
if ( analogRead(MENO) > 1000 && _year > 1900) { _year--; }
sprintf(buffer, "%s: %02d", "Anno", _year);
}
// Set Hour
if ( setModeLevel == 3 ) {
if ( analogRead(PIU) > 1000 && _hour < 24) { _hour++; }
if ( analogRead(MENO) > 1000 && _hour > 1) { _hour--; }
sprintf(buffer, "%s: %02d", "Ora", _hour);
}
// Set Minute
if ( setModeLevel == 4 ) {
if ( analogRead(PIU) > 1000 && _min < 60) { _min++; }
if ( analogRead(MENO) > 1000 && _min > 1) { _min--; }
sprintf(buffer, "%s: %02d", "Minuti", _min);
}
// Set Second
if ( setModeLevel == 5 ) {
if ( analogRead(PIU) > 1000 && _sec < 60) { _sec++; }
if ( analogRead(MENO) > 1000 && _sec > 0) { _sec--; }
sprintf(buffer, "%s: %02d", "Secondi", _sec);
}
tft.print( buffer );
if ( analogRead(SET) > 1000 ) {tft.reset(); setModeLevel++; }
if ( setModeLevel > 5 ) { setModeLevel=0; }
if (timeSet > 0 && (setModeTime*2) < (millis() - timeSet) ) {
RTC.adjust(DateTime(_year, _month, _day, _hour, _min, _sec));
setMode = false;
}
delay(150);
}
}