LCD touchscreen return to beginning of void loop

Hi, i am working on a school project where i need to shoot a tennis ball 12 meters into a bucket. I want to aim with steppers and a simple touch on the screen. Now i have a code where i have the setup of the buckets so my idea was to touch on a button, then the 'gun' moves to the right angle and then with a simple second touch that it shoots and then returns to the projected setup. But i don't know how i go back from 6 buttons to 1 and then back to the 6 buttons.
So first you are gonna see a a little explanation of the project, but you can skip that. then you see the setup of the buckets and if you press for example on bucket 1 you will go to a next screen where if you press it again it will shoot (this is not programmed yet but its quite easy) and after that press i want to go back to the screen with all the 6 buckets.

#if 1

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

char *name = "Jaarproject 6IW"; //edit name of shield

TSPoint tp;

const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button emmer1_btn, emmer2_btn, emmer3_btn, emmer4_btn, emmer5_btn, emmer6_btn;

int pixel_x, pixel_y; //Touch_getXY() updates global vars

bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}

int16_t BOXSIZE;
int16_t PENRADIUS = 1;
uint16_t ID, oldcolor, currentcolor;
uint8_t Orientation = 0; //PORTRAIT

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

void show_tft(void)
{

tft.println("");
tft.setTextSize(3);
tft.println(name);
tft.setTextSize(2);
tft.println("");
tft.println("Wij zijn Maxim, Alexander en Jente van 6IW Viio     tongeren en wij moeten eenafvuurmechanisme ontwerpenom mensen met een handicaptoch op 1 of andere manierhet spelletje bierpong    kunnen spelen. We moeten  een tennisbal in een emmerschieten dat 12m ver staatmaar we mogen niet in 1   keer erin schieten, de balmoet 1 of meerdere keren  botsen. Wij gaan gebruik  maken van luchtdruk door  middel van een vat dat we onder druk zetten en met  een magneetventiel zo de  lucht door te laten naar  de loop waar de tennisbal zit. Dit ventiel gaat opendoor een simpel tikje op  dit LCD scherm.                                       Tik om verder te gaan.");

tft.setTextSize(2);
tft.setTextColor(RED);
tft.setCursor((tft.width() - 48) / 2, (tft.height() * 2) / 4);
tft.print("");
  tft.setTextColor(YELLOW, BLACK);
tft.setCursor(0, (tft.height() * 6) / 8);
//tft.print("Touch screen for loc");
while (1) {
    tp = ts.getPoint();
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    if (tp.z < MINPRESSURE || tp.z > MAXPRESSURE) continue;
    if (tp.x > 450 && tp.x < 570  && tp.y > 450 && tp.y < 570) break;
    tft.setCursor(0, (tft.height() * 3) / 4);
    //tft.print("tp.x=" + String(tp.x) + " tp.y=" + String(tp.y) + "   ");
  }

}

void setup(void)
{
uint16_t tmp;

tft.reset();
ID = tft.readID();
tft.begin(ID);
Serial.begin(9600);
tft.setRotation(Orientation);
tft.fillScreen(BLACK);
show_tft();

uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
if (ID == 0xD3D3) ID = 0x9486; // write-only shield

tft.fillScreen(BLACK);

emmer1_btn.initButton(&tft,  160, 380, 50, 40, WHITE, CYAN, BLACK, "1", 2);

emmer2_btn.initButton(&tft, 107, 240, 50, 40, WHITE, CYAN, BLACK, "2", 2);
emmer3_btn.initButton(&tft, 213, 240, 50, 40, WHITE, CYAN, BLACK, "3", 2);

emmer4_btn.initButton(&tft,  60, 100, 50, 40, WHITE, CYAN, BLACK, "4", 2);
emmer5_btn.initButton(&tft, 160, 100, 50, 40, WHITE, CYAN, BLACK, "5", 2);
emmer6_btn.initButton(&tft, 260, 100, 50, 40, WHITE, CYAN, BLACK, "6", 2);


emmer1_btn.drawButton(false);
emmer2_btn.drawButton(false);
emmer3_btn.drawButton(false);
emmer4_btn.drawButton(false);
emmer5_btn.drawButton(false);
emmer6_btn.drawButton(false);

}

void loop(void)
{

bool down = Touch_getXY();
emmer1_btn.press(down && emmer1_btn.contains(pixel_x, pixel_y));
emmer2_btn.press(down && emmer2_btn.contains(pixel_x, pixel_y));
emmer3_btn.press(down && emmer3_btn.contains(pixel_x, pixel_y));
emmer4_btn.press(down && emmer4_btn.contains(pixel_x, pixel_y));
emmer5_btn.press(down && emmer5_btn.contains(pixel_x, pixel_y));
emmer6_btn.press(down && emmer6_btn.contains(pixel_x, pixel_y));

if (emmer1_btn.justReleased())
    emmer1_btn.drawButton();
    
if (emmer2_btn.justReleased())
    emmer2_btn.drawButton();
if (emmer3_btn.justReleased())
    emmer3_btn.drawButton();
    
if (emmer4_btn.justReleased())
    emmer4_btn.drawButton();
if (emmer5_btn.justReleased())
    emmer5_btn.drawButton();
if (emmer6_btn.justReleased())
    emmer6_btn.drawButton();

if (emmer1_btn.justPressed()) {
    emmer1_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 1"); // after this i want the servo to move and after that i want to press a button and return to the beginning of the void loop
 
}

if (emmer2_btn.justPressed()) {
    emmer2_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 2");  
}
if (emmer3_btn.justPressed()) {
    emmer3_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 3"); 
} 
  
if (emmer4_btn.justPressed()) {
    emmer4_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 4");   
}
if (emmer5_btn.justPressed()) {
    emmer5_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 5");   
}
if (emmer6_btn.justPressed()) {
    emmer6_btn.drawButton(true);
    tft.fillScreen(BLACK); 
    tft.setTextSize(2);
    tft.println("");    
    tft.println("");
    tft.println("even geduld, het geweer   gaat zich nu richten naar emmer 6");  
}

}
#endif`

Vooraf opgemaakte tekst`

Works with different 'screens'. If on the one button screen the button is pressed, blank the screen and open the 6 button screen. If needed blank that screen and open the screen with one button.

What screen do you use? The strings are pretty large or the font is little. 4" ILI9486 is pretty to use with TFT-eSPI and OpenFontRender. Needs a little more RAM.

I use a tft 480x320 with touchscreen.
i programmed that i have a introduction, after you tab on the introduction you see the 6 buttons. If you tab on 1 of them the screen clears the other buttons except the one you selected. Now what i wanna do is if you touch it a second time that you go back to the page with all the buckets. sorry for the bad explanation but it's hard to explain, also because new am with arduino

*because i am new to arduino

wanna. gonna

  • aren’t Arduino or C++ keywords.

Can you fix those, and also fix your code tags in the original post?

Maybe the sticky Forum Guidelines will help.

i don't use those words in the code

By the touch you must check that the other buttons are enable/disable or visible/not visible. You must only check one if the other are in the same state.

If the buttons are enable or visible, you know it is the first touch. If only one is enable or visible, you know it is the second touch.

Edit: isn't it much easier in the Dutch section?

if i tab on 1 of the buttons they all disappearexcept for the one i tabbed on, i programmed it that all the buttons do the same. I just don't know how i go back to the 'screen' with all the buttons

its like when all the buttons disappear except for that 1 button, if i touch it again only the pressed button comes back and not all of them so there is something wrong in the code

what do you mean with this?

This

yeah maybe, thx

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.