• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Problem z kodem w tft LCD
#1
Witam, 
Jestem początkującym i natknąłem się na problem, przez który nie mogę przebrnąć, mianowicie chciałbym zrobić stacje pogody z dotykowego wyświetlacza i na tym wyświetlaczu ekran startowy miałby się odświeżać co 1 min. ale nie wiem jak to ująć w kodzie próbowałem już z biblioteką timers i millis, ale mi nie wychodziło. Bardzo proszę o pomoc z góry dziękuję.
tutaj kod:
Kod:
//#include <Timers.h>
#include <DS3231.h>
#include <SPFD5408_Adafruit_GFX.h>
#include <SPFD5408_Adafruit_TFTLCD.h>
#include <SPFD5408_TouchScreen.h>
#include <Wire.h>

//Timer  mojTimer;

DS3231 clock;
RTCDateTime dt;

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RT 10


#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 Orange  0xFD20      
#define GreenYellow 0xAFE5
#define Navy     0x000F      
#define DarkGreen   0x03E0    
#define DarkCyan  0x03EF    
#define Maroon   0x7800    
#define Purple  0x780F    
#define Olive  0x7BE0      
#define LightGrey  0xC618      
#define DarkGrey  0x7BEF

#define TS_MINX 100
#define TS_MINY 100
#define TS_MAXX 1000
#define TS_MAXY 1000


Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RT);

#define YP A2
#define XM A3
#define YM 8  
#define XP 9

#define MINPRESSURE 200
#define MAXPRESSURE 350


TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

long previousMillis = 0;
int interval = 1000;
char page;


void setup() {
 
tft.reset();
tft.begin(0x9341);
page = 0;
Serial.begin(9600);

 Serial.println("Initialize DS3231");
 Wire.begin();
     clock.begin();
clock.setDateTime(2017, 8, 16, 19, 50, 00);


powitanie();
}
void loop() {
 dt = clock.getDateTime();

 dotyk();

 unsigned long currentMillis = millis();
 if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis;

ekranstartowy();

}
}


void dotyk () {
TSPoint p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE){
p.x = map(p.x, TS_MAXX, TS_MINX, 240, 0);
  p.y = map(p.y, TS_MAXY, TS_MINY,320, 0);
if (page == 0) {


       
  if(p.x>100 && p.x<155 && p.y>50 && p.y<300){
 
 
   
   pinMode(XM, OUTPUT);
   pinMode(YP, OUTPUT);



drawpg ();
 page = 1;
 
}
 
if(p.x>150 && p.x<200 && p.y>50 && p.y<300){
   
 
   
   pinMode(XM, OUTPUT);
   pinMode(YP, OUTPUT);

drawtemp ();
page = 2;
 }
}
}
 if (page == 1) {

 
if(p.x>50 && p.x<100 && p.y>50 && p.y<300){
   
   
   pinMode(XM, OUTPUT);
   pinMode(YP, OUTPUT);


 
ekranstartowy();
 page = 0;
}
}
if (page == 2) {

   

if(p.x>50 && p.x<100 && p.y>50 && p.y<300) {
   
   
   
   pinMode(XM, OUTPUT);
   pinMode(YP, OUTPUT);
   


ekranstartowy();
page = 0;
}
}

}


void ekranstartowy (){

tft.fillScreen(DarkCyan);
tft.setTextSize(2);
tft.setTextColor(Orange);
tft.setCursor(10,10);
tft.print("Data:");
tft.println(clock.dateFormat("d-m-Y", dt)) ;
tft.drawLine(0,33, 10000, 40, Orange);
tft.setCursor(10,40);
tft.print("Godzina:");
tft.println(clock.dateFormat("H:i:s", dt));
tft.drawLine(0,65, 10000, 40,  Orange);
tft.setCursor(10,72);
tft.print("Temperatura:");
tft.setCursor(150,72);
//tft.print(clock.readTemperature());
tft.drawLine(0,95, 10000, 40,  Orange);
tft.fillRect(10,110, 220, 80,  DarkGreen);
tft.setTextSize(3);
tft.setTextColor(Orange);
tft.setCursor(20,120);
tft.print("Pogoda na ");
tft.setCursor(20, 150);
tft.print("polu");
tft.fillRect(10,210, 220, 80, DarkGreen);
tft.setTextSize(3);
tft.setTextColor( Orange);
tft.setCursor(20,220);
tft.print("Temperatura");
tft.setCursor(20, 250);
tft.print("na piecu");

}
void drawpg () {

tft.fillScreen(DarkCyan);
tft.setTextSize(3);
tft.fillRect(10,20,220,80, DarkGreen);
tft.setTextColor(Orange);
tft.setCursor(80,50);
tft.print("<-");
tft.setTextColor (Orange);
tft.setCursor(10, 120);
tft.print("Wilgotnosc");
tft.setTextColor(Orange);
tft.setCursor(10,210);
tft.print("Temperatura");

}

void drawtemp (){

tft.fillScreen(DarkCyan);
tft.setTextColor(Orange);
tft.setTextSize(3);
tft.setCursor(10,150);
tft.print("Temperatutra");
tft.fillRect(10,20,220,80, DarkGreen);
tft.setTextColor(Orange);
tft.setCursor(80,50);
tft.print("<-");

}
void powitanie () {
 tft.fillScreen(DarkCyan);
 tft.setTextColor(Orange);
 tft.setTextSize(4);
 tft.setCursor(50,70);
 tft.print("Witaj");
}
 
Odpowiedź
  


Wiadomości w tym wątku
Problem z kodem w tft LCD - przez Kuba323 - 16-08-2017, 19:44
RE: Problem z kodem w tft LCD - przez adix - 17-08-2017, 14:28
RE: Problem z kodem w tft LCD - przez Kuba323 - 17-08-2017, 14:53
RE: Problem z kodem w tft LCD - przez adix - 17-08-2017, 16:08
RE: Problem z kodem w tft LCD - przez Robson Kerman - 21-08-2017, 21:37
RE: Problem z kodem w tft LCD - przez kaczakat - 26-10-2017, 05:22

Skocz do:


Przeglądający: 1 gości