looping inside a made function

I`m making a interface for some sensors and I made a 2 page menu without any libs.
The pages are 2 functions :

void page1(){
lcd.print("page1");
} 
void page2(){
lcd.print("page2");

When a button (let`s call it -menu button-) is pressed I increment a value to know what page to print.
One of the problems is that I have to check in the page function if the button is pressed.(I made an if statement and it was ok. )
Well, well, another problem. The button triggered the increment function in the "void loop" aswell.
And after a lot of coffee I got something like this :

int wq = 1;//the variable to increment

void page1(){
lcd.print("page1");
if (menu == 1){show(2);}//if I`m in page 1 and I press the button, go to page 2
} 

void page2(){
lcd.print("page2");
if (menu == 1){show(1);}//if I`m in page 2 and I press the button, go to page 1
}

void setup() {
  page1();/print the first page
}

void loop() {
  show(wq);
  wq = show();
}

int show(int p){
 if (p == 1) { page1(); }
       else  { page2(); }
 if(p >= 3)  { p=1;     }
 return p;
}

The error that i get is :

asd.ino: In function 'void loop()':
asd: 49: error: too few arguments to function 'int show(int)'
asd:179: error: at this point in file

The error will highlight the --wq = 1--

(Alot of the code is stripped, if neded I will edit the post)

You wrote the show() function:

int show(int p){

This line (sometimes called the function's signature) says that it must be called using an int data type as an argument. Yet, in loop(), you call it with the statement:

  wq = show();

The compiler is complaining because you didn't pass the expected int to the function.

So I need to call it like this?

if (wq == 1 ) {show(1);}
else { show(2); }

Strange..


Oh, because I have to call it like qw = show(qw);

Whatever show() is expected to do, you wrote it passing in the necessary int data for it to complete its task. If it doesn't need that information passed in, then show() shouldn't have an argument.

Also, the code:

int show(int p){
 if (p == 1) { page1(); }
       else  { page2(); }
 if(p >= 3)  { p=1;     }
 return p;
}

would be easier to read if you place the cursor in the source code window and pressed Ctrl-T, which automatically reformats your code. Also, to me, it would be easier to read if it were written:

int show(int p ){
   switch (p) {
      case 1:
         page1();
        break;
      case 2:
         page2();
         break;
      default:
         p = 1;
         break;
   }
   return p;
}

I'm not sure that's correct because of the way you wrote the if clause, but you can take it from there.

After I modified my code:

int wq = 1;
void setup() {
  lcdsensors();
}
void lcdmenu()
{
 if (btn == 1){lcd.clear();show(1);wq=1;}
}
void lcdsensors()
{
  if (btn == 1){lcd.clear();show(2);wq=2;lcd.clear();}
}
void loop() {  
  show(wq);
}
void show(int p){
 if (p == 1){lcdsensors();}
 else{ lcdmenu();}
}

The switch/case would be a waste of space but ty anyway for the idea.
It`s working now. :smiley: