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)
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.
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.
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.