Hi! I'm noob here so please forgive any obvious mistakes!
I'm trying to create a very simple menu just to understand how it works.
The first page will just have a single button that goes in a second page that has a single back button.
The problem is that it goes back and forth between pages if I press the first button.
Like it auto- presses the back button.
What an I doing wrong?
Thanks!
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(6,5,4,3,2);
UTFT_Buttons myButtons(&myGLCD, &myTouch);
int menu, but1, but2, pressed_button;
boolean default_colors = true;
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myButtons.setTextFont(BigFont);
myButtons.setSymbolFont(Dingbats1_XL);
Serial.begin(9600);
menu1();
menu = 1;
}
void menu1()
{
myGLCD.clrScr();
but1 = myButtons.addButton( 10, 20, 300, 30, "Button 1");
myButtons.drawButton(but1);
menu = 1;
}
void menu2()
{
myGLCD.clrScr();
but2 = myButtons.addButton( 20, 100, 200, 30, "back");
myButtons.drawButton(but2);
menu = 2;
}
void loop()
{
while(1)
{
if (myTouch.dataAvailable() == true)
{
pressed_button = myButtons.checkButtons();
if (menu == 1)
{
if (pressed_button==but1)
menu = 2;
menu2();
}
if (menu == 2)
{
if (pressed_button==but2)
menu = 1;
menu1();
}
}
}
}