Hello!
I want to try out how buttons work with a simple code.
In the beginning a button called "start" appears. When this button is pressed the screen clears and the word "okay" and a new button called "back" appear. When the back-button is pressed the screen shall clear again and the loop begins from the top.
#include <UTFT.h>
#include <ITDB02_Touch.h>
#include <UTFT_Buttons_ITDB.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
UTFT myGLCD(ITDB32WC, 38, 39, 40, 41);
ITDB02_Touch myTouch(6, 5, 4, 3, 2);
UTFT_Buttons myButtons(&myGLCD, &myTouch);
int butStop, pressed_button, butStart, butBack;
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myTouch.InitTouch(1);
myTouch.setPrecision(PREC_HI);
myButtons.setTextFont(BigFont);
myButtons.setSymbolFont(Dingbats1_XL);
void loop(){
boolean back = false;
boolean start = false;
butStart = myButtons.addButton( 20, 90, 280, 60, "START");
myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_BLUE, VGA_AQUA);
myButtons.drawButtons();
while(start == false){
if((myTouch.dataAvailable() == true) && (myButtons.checkButtons() == butStart)){
start = true;
}
}
while(start == true){
myGLCD.clrScr();
butBack = myButtons.addButton( 20, 90, 280, 60, "BACK");
myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_BLUE, VGA_AQUA);
myButtons.drawButtons();
myGLCD.setColor(VGA_WHITE);
myGLCD.print("Okay.", 5, 0);
delay(200);
while(back == false){
myGLCD.setColor(VGA_WHITE);
myGLCD.print("Okay.", 5, 20);
if((myTouch.dataAvailable() == true) && (myButtons.checkButtons() == butBack)){
myGLCD.setColor(VGA_WHITE);
myGLCD.print("Okay.", 5, 40);
back = true;
start = false;
}
}
}
delay(1000);
myGLCD.clrScr();
}
I put an "okay" in every operation that i wanted to check. 2 "okay"s are printed, so the second and third while loop are working well. I guess the problem is that the last if command doesn't work.
Any ideas why?