Help! Is there any way around this Arduino IDE bug where functions declared after void loop() case compiling errors? This is messing up all my legacy code.
Solved my problem! This issue was happening with Arduino IDE 1.6.6. I upgraded to 1.6.9 and it went away. Whew.
Maybe I spoke too soon; it seemed to work fine for a while, and now I am back to “XXX not defined in this scope” when XXX is a function that is below void loop(). Gah!
Simply declare the methods on top.
Like void myFunction(int myParam);
Loop() {
…
}
void myFunction(int myParam) {
…
}
Yeah, that works, @Jurgen_Skrotzky , but it’s very annoying when I have hundreds of legacy programs where the methods are below void loop() and I have to copy paste everything up to the top.
That’s right 
This is the reason I currently working still on arduino ide 1.6.5
I reverted to 1.6.8 and this bug isn’t in it.
I did go to 1.6.9 and I have enough trouble structuring code as it is, without this beasty as well!
@J.P_Saini if you mean plan out the code before starting, then yeah, I should, but I have a more adhoc and organically evolving code structure…
It’s usually a complete mess.
But it works 
I worked out an OK compromise with the help of the Arduino forum: just put the function name void function() at the very top of the program. http://forum.arduino.cc/index.php?topic=410669.0
Note that C/C++ require pre-declaration of functions. In what I think of as a poor decision by the arduino folks, they decided to have their tool try to “guess” at what functions need to have forward declarations and make them and, guess what? It’s a hard thing to do Right™ - as they’re discovering.
Honestly - I think as folks are using Arduino as a tool to learn C/C++, that they should be learning how to do things properly - and this includes forward declarations of methods.
@Daniel_Garcia this was exactly the trap I fell into. I assumed Arduino IDE was teaching me correctly, but it wasn’t. Now I have a trove of legacy code that won’t compile 
it’s always better to split your code into .h and .cpp files. So you can also overload some methods and give them default parameters as well. Really handy. And it is easier to use base classes as well.