Help with some code...


i wondering if 1 me or guide me in correction of following code. can seen in attachment, displaying day of week on lcd display among other information.

i use resetting min , max values @ midnight every day,

code: [select]
#include <adafruit_gfx.h>  
#include <adafruit_qdtech.h>
#include <spi.h>
#include <time.h>  
#include <wire.h>  
#include <ds1307rtc.h>
#include "dht.h"

#define ds1307_i2c_address 0x68
#define sclk 13  
#define mosi 11  
#define cs   9
#define dc   8
#define rst  7

#define dhtpin a0    
#define dhttype dht11
dht dht(dhtpin, dhttype);

adafruit_qdtech tft = adafruit_qdtech(cs, dc, rst);

int tempc = 0;
int humid = 0;
int maxt = -100,mint = 100;
int maxh= -100,minh = 100;
int it;
int ih;

void setup() {

 setsyncprovider(rtc.get);
 dht.begin();
 tft.init();
 tft.setrotation(0);
 tft.fillscreen (qdtech_black);
   
 tft.drawrect(0,  0, 128, 160, qdtech_cyan);
 tft.drawline(0,  40, 128, 40, qdtech_cyan);
 tft.drawline(0,  80, 128, 80, qdtech_cyan);
 tft.drawline(0, 120, 128, 120, qdtech_cyan);
 tft.setcursor(4, 4);
 tft.settextcolor(qdtech_cyan);
 tft.settextsize(1);
 tft.println("time , date:");
 tft.setcursor(4, 44);
 tft.settextcolor(qdtech_cyan);
 tft.settextsize(1);
 tft.println("temperature:");
 tft.setcursor(4, 84);
 tft.settextcolor(qdtech_cyan);
 tft.settextsize(1);
 tft.println("humidity:");
 tft.setcursor(4, 124);
 tft.settextcolor(qdtech_cyan);
 tft.settextsize(1);
 tft.println("dew point:");
     
}
 byte bcdtodec(byte val)  {
 return ( (val/16*10) + (val%16) );
}

void loop() {
 
 int h = dht.readhumidity();
 int t = dht.readtemperature();
 int d = t-((100-h)/5);

 tempc = t;  
 if(tempc > maxt) {maxt = tempc;}
 if(tempc < mint) {mint = tempc;}
 
 humid = h;  
 if(humid > maxh) {maxh = humid;}
 if(humid < minh) {minh = humid;}
 
 tft.setcursor(4, 55);
 tft.settextsize(3);
 tft.settextcolor(qdtech_grey,qdtech_black);
 tft.print(tempc);
 tft.settextsize(2);
 tft.print((char)247);
 tft.print("c  ");
 
 tft.settextsize(1);
 tft.settextcolor(qdtech_red,qdtech_black);
 tft.setcursor(75,55);
 tft.print(maxt);
 tft.print((char)247);
 tft.print("c");
 tft.print(" max");
 tft.settextcolor(qdtech_blue,qdtech_black);
 tft.setcursor(75,65);
 tft.print(mint);
 tft.print((char)247);
 tft.print("c");
 tft.print(" min");
 
 tft.setcursor(4, 95);
 tft.settextsize(3);
 tft.settextcolor(qdtech_grey,qdtech_black);
 tft.print(humid);
 tft.settextsize(2);
 tft.print(" %");
 
 tft.settextsize(1);
 tft.settextcolor(qdtech_red,qdtech_black);
 tft.setcursor(75,95);
 tft.print(maxh);
 tft.print("%");
 tft.print(" max");
 tft.settextcolor(qdtech_blue,qdtech_black);
 tft.setcursor(75,105);
 tft.print(minh);
 tft.print("%");
 tft.print(" min");
 
 tft.setcursor(4, 135);
 tft.settextsize(3);
 tft.settextcolor(qdtech_grey,qdtech_black);
 tft.print(d);
 tft.settextsize(2);
 tft.print((char)247);
 tft.print("c  ");
 
 tft.settextsize(2);
 tft.settextcolor(qdtech_grey,qdtech_black);
 tft.setcursor(4, 18);
 printdigits(hour());
 tft.print(":");
 printdigits(minute());
 tft.settextsize(1);
 tft.setcursor(75, 26);
 printdigits(day());
 tft.print("/");
 printdigits(month());
 
 printday();
 
}

void printdigits(int digits){
 if(digits < 10)
 tft.print('0');
 tft.print(digits);
}

void printday(){

 int weekday = (bcdtodec(wire.read()))-160; //0-6 -> sunday - saturday
 
 tft.setcursor(75, 16);
 tft.settextcolor(qdtech_grey,qdtech_black);
 switch(weekday){
    case 1:
    tft.print("monday");
    break;
    case 2:
    tft.print("tuesday");
    break;
    case 3:
    tft.print("wednesday");
    break;
    case 4:
    tft.print("thursday");
    break;
    case 5:
    tft.print("friday");
    break;
    case 6:
    tft.print("saturday");
    break;
    case 0:
    tft.print("sunday");
    break;

 }
}

i can't see logic of code within calls tft.

it won't solve problem make code easier read if tft stuff put functions meaningful names.

how know when midnight? once can detect should simple matter reset min , max values.

...r


Arduino Forum > Using Arduino > Programming Questions > Help with some code...


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support