Another beginners question here, hopefully you guys can help.
I am making a touch screen display for my boats control panel, it will display a main screen showing temperatures of various places (engine, inside temp, outside temp, water temp and a clock)
i am trying to set it up so that when I press a button on the screen it takes me to another screen with detailed info on it.
I am looking for a way to do this so that i can return to the "main menu" screen again.
basically something similar to the goto function (which i understand i shouldnt use as there is always a way round it using other functions)
I have included my sketch which you will probably think is quite messy but please bear in mind I am still learning
#include <DS3231.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_tinyFAT.h>
#include <tinyFAT.h>
#include <Wire.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
char* files480[]={"pic998.RAW, pic1000.RAW"};
char* files[10];
int picsize_x, picsize_y;
word res;
UTFT myGLCD(ITDB43,38,39,40,41);
UTFT_tinyFAT myFiles(&myGLCD);
DS3231 rtc(SDA, SCL);
UTouch myTouch( 6, 5, 4, 3, 2);
int val;
int tempPin = 2;
int val2;
int tempPin2 = 3;
int val3;
int tempPin3 = 4;
int x, y;
void waitForIt(int x1, int y1, int x2, int y2)
{
while (myTouch.dataAvailable())
myTouch.read();
}
void setup()
{
Serial.begin(115200);
myGLCD.InitLCD();
file.initFAT();
rtc.begin();
myTouch.setPrecision(PREC_MEDIUM);
myTouch.InitTouch();
myGLCD.setColor(255,255,255);
myGLCD.setFont(SmallFont);
picsize_x=myGLCD.getDisplayXSize();
picsize_y=myGLCD.getDisplayYSize();
switch (picsize_x)
{
for (int z=0; z<sizeof(files480)/sizeof(*files480);z++)
files[z] = files480[z];
}
}
int var = 100;
void loop()
{
// int buf[478];
// int x, x2;
// int y, y2;
// int r;
// DRAW THE PATTERN AND LOGO
myGLCD.clrScr();
myGLCD.setColor (255,0,0);
for (int i=15; i<256; i+=5)
{
myGLCD.drawLine(1, i, (i*1.88)-10, 256);
}
myGLCD.setColor (255,0,0);
for (int i=256; i>15; i-=5)
{
myGLCD.drawLine(478, i, (i*1.88)-11, 15);
}
myGLCD.setColor (0,255,255);
for (int i=256; i>15; i-=5)
{
myGLCD.drawLine(1, i, 491-(i*1.88), 15);
}
myGLCD.setColor (0,255,255);
for (int i=15; i<256; i+=5)
{
myGLCD.drawLine(478, i, 490-(i*1.88), 256);
}
{
res=myFiles.loadBitmap(75, 105, 330, 60, "pic1000.RAW");
}
delay(5000);
myGLCD.clrScr();
// DRAW THE MAIN SCREEN
{
myGLCD.setBackColor (0,0,0);
res=myFiles.loadBitmap(0, 0, picsize_x, picsize_y, "pic998.RAW");
while(var < 200)
{
// DRAW TIME, DAY & DATE
myGLCD.setFont(SmallFont);
myGLCD.setColor (255,255,255);
myGLCD.print(rtc.getDateStr(), 355, 73);
myGLCD.print(rtc.getDOWStr(), 60, 73);
myGLCD.setColor (255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print(rtc.getTimeStr(), 180, 71);
{
// MATHS FOR LM35 TEMP SENSORS
val = analogRead(tempPin);
float mv = (val / 1024.0) * 5000;
float cel = mv / 10;
val2 = analogRead(tempPin2);
float mv2 = (val2 / 1024.0) * 5000;
float cel2 = mv2 / 10;
val3 = analogRead(tempPin3);
float mv3 = (val3 / 1024.0) * 5000;
float cel3 = mv3 / 10;
// PRINT TEMPS TO TFT
myGLCD.printNumF(rtc.getTemp(), 1, 279, 158);
myGLCD.printNumF(cel, 1, 279, 120);
myGLCD.printNumF(cel2, 1, 279, 197);
myGLCD.printNumF(cel3, 1, 279, 234);
}
// TOUCH SCREEN COMMANDS
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=10) && (y<=60)) // Upper row
{
if ((x>=10) && (x<=60)) // Button: 1
{
waitForIt(10, 10, 60, 60);
int var2 = 100;
while (var2 < 200)
{
myGLCD.setFont(BigFont);
myGLCD.clrScr();
res=myFiles.loadBitmap(0, 0, picsize_x, picsize_y, "pic998.RAW");
delay (2000);
myGLCD.clrScr();
res=myFiles.loadBitmap(75, 105, 330, 60, "pic1000.RAW");
delay (2000);
// THIS IS WHERE I NEED HELP - I AM LOOKING FOR A WAY TO EXIT THE while COMMAND
// AND RETURN TO THE MAIN SCREEN
}}}}
else
{myGLCD.print("FAIL", CENTER, CENTER);
}
}}}