I am having some issues. I'm new to Arduino as well as C++ and have been tinkering with an environmental controller I want to build for my terrarium. I have borrowed some code, most of it from multiple projects throughout the web who have offered their sketches to the public. I have gotten 3 of my 5 relays working and I'm now working on the display TFTLCD since it just came in 5 days ago. It's been 16hrs a day trying to decipher what I'm doing since then.
Basically I'm trying to create a menu page using the drawPage (); syntax... So if the button area is pressed it will pull the "void drawPage() {}" it corresponds to.
Please don't hate on me for being a noob, and not knowing terminology etc.. but it seems like some of my "if" statements aren't working right now, and I'm probably going about this the wrong way entirely, but I've tried 10 different ways and this seems the easiest way to call a page up to me... Is there anything that looks wrong with this code? The top half directing the button/pressed area to the "void drawMenu () {}" works fine, but when I press the button on the home page and it goes to the menu it displays the menu page and immediately reverts back to the "drawHome" page or currentpage = 0. I tried adding another if statement saying basically if there was no pressure to make currentpage == 1 and it worked for getting from home page to menu page but then the home button does not work on the menu page as if it doesn't exist. Like it's only grabbing my "TSPoint p = ts.getPoint();" only checks pressure on the home page. I know my plot points for my buttons aren't exactly right, I've searched but cant figure out how to plot points for a button yet. I've worked on this basically non stop for 4 weeks now. I'm far from finished. I still gotta get the pages to show up, then figure out how to get the settings to be programmed in on those pages so I can change heating, cooling, humidity, lighting and run a fan on my 8 relay board. I am using an Arduino Mega 2560 and will comment back with full code in a bit after I clean it up so I don't get heckled for it. lol
ORIGINAL CODE I TRIED (MENU PAGE IMMEDIATELY LOOPS BACK TO HOME PAGE)
void loop() {
digitalWrite(13,HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13,LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (currentpage == 0) {
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// Check if MENU BUTTON is chosen
if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
Serial.print("Menu Selected");
currentpage = 1;
delay(10);
drawMenu();
}
} //END CURRENTPAGE 0
if (currentpage == 1) {
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// Check if Home BUTTON is chosen
if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
Serial.print("Home Selected");
currentpage = 0;
delay(10);
drawHome();
}
} //END CURRENTPAGE 1
) //END VOID LOOP
CODE WITH FIX I TRIED
void loop() {
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// Check if MENU BUTTON is chosen
if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
Serial.print("Menu Selected");
currentpage = 1;
delay(10);
drawMenu();
}
} //END CURRENTPAGE 0
if (currentpage == 1) {
//ADDED THIS IF STATEMENT AS A FIX, menu page stays active now but home button on menu page doesn't return to home if pressed.
if (p.z = 0) {
currentpage == 1;
} //END OF FIX
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// Check if Home BUTTON is chosen
if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
Serial.print("Home Selected");
currentpage = 0;
delay(10);
drawHome();
}
} //END CURRENTPAGE 1
) //END VOID LOOP