can i ask an If inside a switch case if so how is it done
ie
case 0: // value1---- 2 options from here
if (somthing == somthing else)
{
Serial.println("done it")
}
else
Serial.println("option 2 inside case 1");
break;
case 1: // value 2 ----- 2 more options here
if (somthing == somthing)
{
Serial.println("may have done it")
}
else
Serial.println("Option 2 inside case 1");
break
Using ifs inside cases is perfectly valid but, of course, in your example
if (somthing == somthing)
will always be true, but I suspect that you did not mean what you wrote
Please post your whole program or a short example that exhibits the problem and a description of what happens and what you think should happen when you run it.
While C++ doesn't allow spaces in variable names (FORTRAN does), and his/her code won't actually compile, the idea was to compare two different things.
While C++ doesn't allow spaces in variable names (FORTRAN does), and his/her code won't actually compile, the idea was to compare two different things.
if (answer= a);
{
Serial.println("Option1 Screen 1");
}
else
The body of the if statement is that ; on the end. Then, you have a useless set of curly braces delimiting a block of code. Then, you have an else statement that does not follow an if statement.
Now, why might this be better? Suppose you have 4 buttons. You can have 4 ugly, complex, redundant if statements, or you can have 16 simple if statements. Right? Well, no. You don't actually need 16 if statements for 4 buttons. If buttons 1 and 2 are on the same row, and buttons 3 and 4 are on the next row, and lined up, then you only need to test that p.x is greater than the left edge of one button to test that the press is in either button 1 or button 3. Similarly, the p.x value will be less than some value for the press to be in 1 or 3. So, two tests, and you know that the press could be in one of two buttons. Two more tests, and you know that it could be buttons 2 or 4. Two more tests to confirm the possibility of being 1 or 3 or 2 or 4. Hmmm, words are not helping all that much. But, for more than 2 buttons, nested if statements are far easier to deal with. And, of course, it is easy to add else statements and Serial.print() statements, to confirm that the left, right, top, and bottom tests are, or are not, successful, to see if the test results match your expectations.
PaulS:
The snippets of code you have posted don't do any more than print that a particular button has been pressed.
If your real code does more than that, and you need help with it, you need to post it.
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