I am looking to organize a huge sketch with several libraries and many, many functions to deal with separate things.
I thought I would be able to write code inside of tabs as if they are literally a part of the main ino file.
However this appears to not be the case when you utilize functions that accept arguments.
When you use a function that needs to accept an argument in a separate tib the compiler throws many errors about how the function isn't defined.
I have attached a small example sketch of this phenomenon.
Is this normal and in proper working order for arduino?
How do I incorporate functions that take arguments into multiple sketch tabs properly?
side note: why does it matter where I put functions in my sketch? Aren't user defined functions generated first and then the compiler works on the "setup" and "loop" functions?(the sketch also shows what I mean)
Code from examplesOfFunctionsOnDifferentTabs.ino
int fecal(int poopy = 0){
return poopy;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(worksFine()); //function that doesnt accept arguments works fine across tabs
Serial.println(fecal(1)); //function that accepts an arg that is before the function call works fine also
Serial.println(poopie(2)); // function that is called before the line in the sketch that it was defined does not work
Serial.println(poop(4)); // function that takes an argument that is defined across tabs does not work
Serial.println(dingleberry(4)); // function that is defined at the end of the sketch doesnt work even though i see this done in example sketches
}
int poopie(int poopy = 0){
return poopy;
}
void loop() {// put your main code here, to run repeatedly:
}
int dingleberry(int poopy = 0){
return poopy;
}
Code from a separate tab in project(aka a different file inside of sketch folder
int worksFine(){
return 0;
}
int poop(int poopy = 0){
return poopy;
}
Error Output:
C:\Users\steve\Documents\Arduino\exampleOfFunctionsOnDifferentTab\exampleOfFunctionsOnDifferentTab.ino: In function 'void setup()':
exampleOfFunctionsOnDifferentTab:10: error: 'poopie' was not declared in this scope
Serial.println(poopie(2)); // function that is called before the line in the sketch that it was defined does not work
^
exampleOfFunctionsOnDifferentTab:11: error: 'poop' was not declared in this scope
Serial.println(poop(4)); // function that takes an argument that is defined across tabs does not work
^
exampleOfFunctionsOnDifferentTab:12: error: 'dingleberry' was not declared in this scope
Serial.println(dingleberry(4)); // function that is defined at the end of the sketch doesnt work even though i see this done in example sketches
^
exit status 1
'poopie' was not declared in this scope
exampleOfFunctionsOnDifferentTab.zip (806 Bytes)