Here's the code. I know there are some things missing, but that's not important for me right now..
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
TFT screen = TFT(cs, dc, rst);
// position of the line on screen
int xPos = 0;
int offset=40; //offset vertical position graph
int graphHeight=40;
int RLux=10;
const int buttonPin=2;
int buttonState = 0;
int lastButtonState=0;
int standby;//standby Power (W)
int standbyGraph;
char t[3];
char l[5];
char p[6];
void setup() {
pinMode(buttonPin,OUTPUT);
// initialize the display
screen.begin();
// clear the screen with a pretty color
screen.background(204,229, 255);
// initialize the serial port
Serial.begin(9600);
Serial.println("Choose your standby Temperature (Power):");
while(Serial.available()==0){
screen.stroke(0, 0, 0); //posso meter isto dentro da função createSquare
screen.setTextSize(2);
screen.text("Go to \n Serial Port", 12, 40); //Texto -7 nos yy
}
screen.background(204,229, 255);
standby=Serial.parseFloat();
delay(2000);
createSquare(0, 9);
screen.stroke(0, 0, 0); //posso meter isto dentro da função createSquare
screen.setTextSize(1);
screen.text("Power (W)", 2, 2); //Texto -7 nos yy
createSquare(0,95);
screen.stroke(0, 0, 0);
screen.setTextSize(1);
screen.text("Lux", 2, 88); //Texto -7 nos yy
createSquare(82,9);
screen.stroke(0, 0, 0);
screen.setTextSize(1);
screen.text("$", 84, 2); //Texto -7 nos yy
createSquare(82,95);
screen.stroke(0, 0, 0);
screen.setTextSize(1);
screen.text("Temp. (C)", 84, 88); //Texto -7 nos yy
}
void loop() {
int sensorVal0=analogRead(A0);
int drawHeight = map(sensorVal0, 0, 1023, 0, graphHeight);
float volt0=(sensorVal0*5.0)/1024.0;
float current=volt0*10.0; //max current = 50 A
int power=current*230;
String PowerVal=String(power);
PowerVal.toCharArray(p,6);
// read the sensor and map it to the screen height
int sensorVal1 = analogRead(A1);
float volt1 = (sensorVal1/1023.0)*5.0;
int temp=(volt1-.5)*100;
String TempVal=String(temp);
TempVal.toCharArray(t,3);
int sensorVal2=analogRead(A2);
float volt2= sensorVal2*0.0048828125;
int lux = 500/(RLux*((5-volt2)/volt2));
String LuxVal=String(lux);
LuxVal.toCharArray(l,5);
//valores todos escritos aqui!
screen.stroke(0, 0, 0);
screen.setTextSize(3);
screen.text(l, 2, 102); //Show Lux
screen.text(t, 102, 102); //Show Temp
screen.text(p,2, 16); //Show Power
screen.text(t,102,16); //Show Cost
if(lux>500){
warning();
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
//WANT TO EXIT LOOP
}
else {
//STAY IN THE LOOP, REPETING WARNING JUST ONCE
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
/*
if(temp<=standby){
screen.stroke(0, 230, 0); //GREEN
screen.line(xPos, offset+(graphHeight - drawHeight), xPos, offset+graphHeight);
}
else{
screen.stroke(255,0, 0); //RED
screen.line(xPos, offset+(graphHeight - drawHeight), xPos, offset+graphHeight);
}
*/
if (xPos >= screen.width()) {
xPos = 0;
//screen.background(255, 255, 255);
}
else {
// increment the horizontal position:
xPos++;
}
delay(1000);
//LIMPAR TODOS OS VALORES (clean all values)
createSquare(0,95);
createSquare(0, 9);
createSquare(82,9);
createSquare(82,95);
}
void createSquare(int x0, int y0){
screen.stroke(255, 250, 100); //YELLOW
screen.fill(255, 250, 100); //graph's rectangle background YELLOW
//square da Temp.
return screen.rect(x0, y0, 78, 33);
}
void warning(){
screen.noFill();
screen.stroke(0, 0, 0); //RED
screen.rect(10,40, screen.width()-25, screen.height()-60);
screen.fill(255,255,255);
screen.stroke(255, 0, 0); //RED
screen.rect(11,41, screen.width()-27, screen.height()-62);
screen.stroke(0, 0, 0); //RED
screen.setTextSize(2);
screen.text("AVISO",25,45);
screen.textSize(1);
screen.text("Lux Limit Exceeded",35,55);
}