if statement inside a switch case can it be done

code posted i know it just posts to serial screen i just didn't want the screen jumping all over the place until i can see output in the serial monitor

So, do you have a problem, or not?

yes the code does not work

when the statement is true in any of the options it won't run the event

if ((p.x > 137 && p.x < 210)&& (p.y > 280 && p.y < 320)) { <<< if this is true
Serial.print("option1");} <<<<< this does not run

on any of the if statements i'm getting nothing in the serial monitor apart from the XY coordinates and the value of page

if i press button 2 i get the following output in the serial monitor

X 155 = 314 Y
1

also i should be getting
option1

There doesnt appear to be any breaks in your switch statement, is this intentional? I'm thinking not.

switch( value )
{
  case 0:

  break;  // I appear to be missing!
}

tammytam:
There doesnt appear to be any breaks in your switch statement, is this intentional? I'm thinking not.

switch( value )

{
  case 0:

break;  // I appear to be missing!
}

well spotted but unfortunately no still doesn't run the Serial.print

i have just had a thought is it possible the page value isnt being taken into consideration
could the problem be here ??

   char command = page;
   switch (command)

when the statement is true in any of the options it won't run the event

if ((p.x > 137 && p.x < 210)&& (p.y > 280 && p.y < 320)) { <<< if this is true
Serial.print("option1");} <<<<< this does not run

Why do you ASSUME that the statement is true?

 Serial.print(" X "); Serial.print(p.x);
  Serial.print("\t = "); Serial.print(p.y);
  Serial.println(" Y ");

You REALLY need to work on this. Why would you print something like " X 150 tab = 350 Y ", when "X=150 tab Y=350" makes more sense?

Break your complex if statement into 4 simple if statements, with else blocks. You will quickly find out where your assumptions are wrong.

ok here you go

//---------------------- Main Loop ----------------------------
void loop() {
  ctp.begin();
  Serial1.begin(115200);
  Serial.begin(115200);
  
  // Wait for a touch 
  if (! ctp.touched()) {
    return;
  }

  // Retrieve a point  
  TS_Point p = ctp.getPoint();
  
 // flip it around to match the screen.
  p.x = map(p.x, 240, 0, 240, 0);
  p.y = map(p.y, 320, 0, 0, 320);
  
if(p.x > 137)
{Serial.println("p.x is more than 137");}
if(p.x < 210)
{Serial.println("p.x is less than 210");}
if(p.y > 280)
{Serial.println("p.y is more than 280");}
if(p.y < 320)
{Serial.println("p.x is less than 320");}
{

output to screen on push of button 1

p.x is more than 137
p.x is less than 210
p.y is more than 280
p.x is less than 320
 X 200 & Y 312  Page Value= 1

so everything is true

there is something in the case that is wrong

there is something in the case that is wrong

Could be. Of course, you'll need to visit http://snippets-r-us.com for help with your snippets.

Right job done the question was answered correctly within 20 mins from stack overflow

instead of
case '1':
i used
case 1:
job done

Right job done the question was answered correctly within 20 mins from stack overflow

instead of
case '1':
i used
case 1:
job done

Can you highlight the line in the last snippet of code that you posted where you made that change?

Clearly, you provided more information on stack overflow than you did here!

the code was as follows and it was just a simple mistake

int a = page;
switch (a) {

// --------------check to see if screen 1 is loaded-----------------

case '1': { // Screen 1 Active As when screen 1 loads it changes the value of page to 1
if ((p.x > 137 && p.x < 210)&& (p.y > 280 && p.y < 320)) {
mainmenu();}
else if ((p.x > 80 && p.x < 112)&& (p.y > 280 && p.y < 320)) {
Serial.print("option1.2");}

the code in red above was supposed to be as below in bold but without the inverted commas

case 3: { // Screen 3 Active As when screen 3 loads it changes the value of page to 3
if ((p.x > 137 && p.x < 210)&& (p.y > 280 && p.y < 320)) {
Serial.print("option3.1");}

and all i did was copy and paste the info from this site to stack overflow and it was just luck the right person came and saw it

i now have a full working sample for anyone who wants to use this code for a base for a touch screen menu for this type of screen the Adafruit 2.8" TFT Touch Shield v2 - with Capacitive touch
can be downloaded from here

https://github.com/mikewitney/SampleTouch

i know its not perfect but it works and can be a starter for other people
as there are very little results for searching for this touch screen