first half of code (its too large and i can only make 1 post every 5 min ><):
#include <memorysaver.h>
#include <UTFT.h>
#include <URTouch.h>
#include <SD.h> //SD card library
#include <Wire.h>
#include <SPI.h>
#include <DHT.h>
#include <Time.h>
#include <DS1307RTC.h>
#define DHTPIN A0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
UTFT myGLCD(ITDB32S,38,39,40,41); //pins used for TFT
URTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t BigFont[]; //Which fonts to use...
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];
float gfLineVoltage = 235.0f; // typical effective Voltage in Germany
float gfACS712_Factor = 75.76f; // use 50.0f for 20A version, 75.76f for 30A version; 27.03f for 5A version
unsigned long gulSamplePeriod_us = 100000; // 100ms is 5 cycles at 50Hz and 6 cycles at 60Hz
int giADCOffset = 512; // initial digital zero of the arduino input from ACS712
int ttdht = 0;
int ttcls = 0;
int ttac = 0;
int touchx;
int touchy;
File myFile;
// START AC CURRENT SENSOR //
float ACSensorPoll () {
float fCurrentRMS = 0;
long lNoSamples=0;
long lCurrentSumSQ = 0;
long lCurrentSum=0;
// set-up ADC
ADCSRA = 0x87; // turn on adc, adc-freq = 1/128 of CPU ; keep in min: adc converseion takes 13 ADC clock cycles
ADMUX = 0x43; // internal 5V reference
// 1st sample is slower due to datasheet - so we spoil it
ADCSRA |= (1 << ADSC);
while (!(ADCSRA & 0x10));
// sample loop - with inital parameters, we will get approx 800 values in 100ms
unsigned long ulEndMicros = micros()+gulSamplePeriod_us;
while(micros()<ulEndMicros)
{
// start sampling and wait for result
ADCSRA |= (1 << ADSC);
while (!(ADCSRA & 0x10));
// make sure that we read ADCL 1st
long lValue = ADCL;
lValue += (ADCH << 8);
lValue -= giADCOffset;
lCurrentSum += lValue;
lCurrentSumSQ += lValue*lValue;
lNoSamples++;
}
// stop sampling
ADCSRA = 0x00;
if (lNoSamples>0) // if no samples, micros did run over
{
// correct quadradic current sum for offset: Sum((i(t)+o)^2) = Sum(i(t)^2) + 2*o*Sum(i(t)) + o^2*NoSamples
// sum should be zero as we have sampled 5 cycles at 50Hz (or 6 at 60Hz)
float fOffset = (float)lCurrentSum/lNoSamples;
lCurrentSumSQ -= 2*fOffset*lCurrentSum + fOffset*fOffset*lNoSamples;
if (lCurrentSumSQ<0) {lCurrentSumSQ=0;} // avoid NaN due to round-off effects
fCurrentRMS = sqrtf((float)lCurrentSumSQ/(float)lNoSamples) * gfACS712_Factor * gfLineVoltage / 1024;
// correct offset for next round
giADCOffset=(int)(giADCOffset+fOffset+0.5f);
}
return fCurrentRMS;
}
// END AC CURRENT SENSOR //
struct Element {
int pageID;
int sX; //start X
int sY; //start Y
int eX; //end X
int eY; //end Y
int radius; //for round elements
int font; //1 smallfont, 2 bigfont, 3 sevensegnumfont
int type; // 1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle
int colorR; //font-color
int colorG;
int colorB;
int BGcolorR; //background color for text or fill color for objects
int BGcolorG;
int BGcolorB;
int BordercolorR; //border color
int BordercolorG;
int BordercolorB;
int ABordercolorR; //border color when pressed
int ABordercolorG;
int ABordercolorB;
bool redraw;
String label; //for buttons or text display in a box
};
Element pageElements[] = {
{ //element 1
1, //page ID
11,
22,
110,
40,
123,
1,
4,
255, //r
1, //g
2,//b
3,//r
255, //g
0,//b
5,//r
6,//g
7,//b
8,
9,
88,
1,
"Button Label"
},
//element 2
{
1, //page ID
11,
60,
110,
88,
123,
1,
4,
0, //r
255, //g
2,//b
255,//r
0, //g
0,//b
0,//r
0,//g
255,//b
8,
9,
88,
1,
"Button 2"
},
//element 3
{
1, //page ID
11,
90,
110,
114,
123,
1,
4,
0, //r
255, //g
2,//b
255,//r
0, //g
0,//b
0,//r
0,//g
255,//b
8,
9,
88,
1,
"Button 3"
}
};
void DrawCircle (int elementID) {
myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
myGLCD.drawCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}
void DrawRectangle (int elementID) {
myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
myGLCD.drawRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}
void DrawRoundRectangle (int elementID) {
myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
myGLCD.drawRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}
void FillCircle (int elementID) {
myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
myGLCD.fillCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}
void FillRectangle (int elementID) {
myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
myGLCD.fillRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}
void FillRoundRectangle (int elementID) {
myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
myGLCD.fillRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}
void DrawButton (int elementID) {
FillRoundRectangle(elementID);
DrawRoundRectangle(elementID);
DrawTextBox(elementID);
}
void SetFont (int font){
switch (font){
case 1:
myGLCD.setFont(SmallFont);
break;
case 2:
myGLCD.setFont(BigFont);
break;
case 3:
myGLCD.setFont(SevenSegNumFont);
break;
}
}
void DrawTextBox (int elementID) {
myGLCD.setColor(pageElements[elementID].colorR, pageElements[elementID].colorG, pageElements[elementID].colorB);
myGLCD.setBackColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
SetFont(pageElements[elementID].font);
myGLCD.print(pageElements[elementID].label, pageElements[elementID].sX+3, pageElements[elementID].sY+3);
}
void DrawDone (int elementID) {
pageElements[elementID].redraw = 0;
}
void DrawPage (int pageID) {
for(int i=0; i<= 3; i = i +1){
if (pageID == pageElements[i].pageID) {
if (pageElements[i].redraw == 1){
switch(pageElements[i].type){ // 1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle, 6 = filled rectangle, 7 = filled round rectangle, 8 = filled circle
case 1:
DrawButton(i);
DrawDone(i);
break;
case 2:
DrawRectangle(i);
DrawDone(i);
break;
case 3:
DrawRoundRectangle(i);
DrawDone(i);
break;
case 4:
DrawTextBox(i);
DrawDone(i);
break;
case 5:
DrawCircle(i);
DrawDone(i);
break;
case 6:
FillRectangle(i);
DrawDone(i);
break;
case 7:
FillRoundRectangle(i);
DrawDone(i);
break;
case 8:
FillCircle(i);
DrawDone(i);
break;
}
}
}
}
}
void setup() {
Serial.begin(9600);
pinMode(46, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
dht.begin();
myGLCD.InitLCD(LANDSCAPE); //LANDSCAPE or PORTRAIT
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
SD.begin(53);
}