Go Down

Topic: Problem with code (Read 90 times) previous topic - next topic

Kuba323

Hi,

I need help with my tft lcd touch screen. I want make weather station with rtc, temperature, humidity etc.
I want to refresh my screen every 1 min. It's my code:
Code: [Select]
#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);



char page;



void setup() {
 
tft.reset();
tft.begin(0x9341);
page = 0;
Serial.begin(9600);
 
  Serial.println("Initialize DS3231");
clock.begin();
 clock.setDateTime(2017, 8, 14, 18, 25, 00);
mojTimer.begin(3000);

powitanie();
}
void loop() {
  dt = clock.getDateTime();
  dotyk();
 
 
if (mojTimer.available()) {
//tft.fillScreen(BLACK);
ekranstartowy();
mojTimer.restart();

}
  }


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", 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");
}

But it isn't working
https://www.youtube.com/watch?v=a65c3_uOTpg
Plese help and sorry for my broken english.

Coding Badly


@Kuba323, please do not cross-post.  Other post removed.


Go Up