function was not declared in this scope

So I was debugging my code I made a small change to the code to put some data on an LCD display that I had attached to my Arduino 2560. I had done this several time before just looking at what my code was doing and making modifications. Each time, it compiled without error.

So after adding this "LCD.print" statement, I got a compile error "LCD_power_on" was not declared in this scope."

This was interesting since I made no changes to my function LCD_power_on and it had compiled several times before. I also made no changes in my main program (014-xxxx_Rev0) that calls this function.

It was a rather sudden compile error with no real reason to pop the error. The function is in under the tab "Display".

I tried commenting out the line and what I found was that all of the "Display" functions are having this error. I tried to include Display.ino but what I got then was my "LCD" call out in my main program for the SoftwareSerial creation for LCD with a not declared in this scope in the subprogram "Display".

So things are definitely not working as normal. Attached are my program files.

014-xxxx_Rev0.ino (6.35 KB)

Display.ino (10.9 KB)

Error_handling.ino (6.5 KB)

Ground_Fault_Test.ino (9.84 KB)

Initialize_Outputs.ino (1.59 KB)

Mux_Setup.ino (10.4 KB)

Test_App_Communication.ino (20.8 KB)

Troubleshoot.ino (12.1 KB)

Which program file do you want help fixing?

Ok I took a bite as I am a bit well needing a break from a project I am working on.

First, I see what you are trying to do and there are better ways, if you want to treat this as an object build a class and use the class You have missing files.

I would like to alter 014-xxxx_Rev0 to make this work. All the other files are just function holders. Code basically that I can reuse and have reused.

014-xxxx_Rev0 is my main program. Basically, when I compile it, I get LCD_power_on was not declared in this scope.

Everything was compiling just fine, but suddenly stopped.

I tried figuring out what I did wrong. As I was programming, I didn't need an include file for any ino files. I did have to have them for any ".h" header file. Now it looks like I need to include all my ".ino" files as well.

To me, this seems like a bug.

It's like it wants me now to add an include for each ino and for each ino that uses a ino that uses a function outside of itself to have an include for it as well.

This is unusual in that it wasn't a compiler requirement before.

My guess is that your problem has to do with the Arduino IDE's technique of .ino file concatenation and automatic prototype generation. I image the errors might vary from version to version of the IDE as the latter process seems to be evolving.

Do yourself a favor -- if you're going to attempt to write modular, multi-file code (a good idea in general), then learn to properly use .h and .cpp files. And provide all of your own function prototypes. See:
Reply #3 Here: How to properly include functions written on other sketch tabs - #4 by gfvalvo - Programming Questions - Arduino Forum
and
Reply #5 Here: Multiple variable definition error when compiling with .h and .cpp file tabs - #6 by gfvalvo - Programming Questions - Arduino Forum

In the end, you should only have one .ino file.

Here,

I have done you a simple task that I hope helps you. I have created a fully fledged zip that will add a new class to your Arduino libs. It will be called SampleClass.

It has an example, so you can even go to examples, and see how the code works.

Examine the code, see what i did, it is a simple class, but I hope it gets you thinking. Excuse the formatting, did this on the train.

So you can load this with Lib manager and load the zip, it will install just like any other lib, and it has to functions. add multi. There is an example program as i said, feel free to check it out.

Use this as and Idea as to how you can use code re-usability. I could have called this class Math and did all my math calls in here.

SampleClass.zip (2.07 KB)

Now, just to show you some power you have. Lets take that first class. In only deals with ints, what if i want floats? Or some other data type.

This new version has a new class and new example. SampleClassTemplate, and you will find an example. It is a template class and allows you expand the functionality of your libs even more.

SampleClass.zip (2.8 KB)

The { } in loop() are not balanced. All the code in the other tabs is inside loop().

Ok, I have only one ino file and rest ".h". This seems to be working much better. I still have to be mindful about my "#include" statements since you can get a "redefinition" error if it gets defined by two functions.

I had my main program (014-xxxx_Rev0_1.ino) including Mux_Setup.h and Ground_Fault_Test.h including Mux_Setup.h.

This was because Ground_Fault_Test calls a function in Mux_Setup.h.

I like the class definition method. It's very clean. I think I will pursue that.

I also liked the template as well.

Thanks for the information. It is very helpful in helping me organize my programs. I'm still not sure on how the ino files became "un-linked", but linking them back up via ".h" is more inline with what I do anyway.

Thank you Romonaga for the examples. This is very good information that I will use in the future.

varnonga:
Ok, I have only one ino file and rest ".h". This seems to be working much better. I still have to be mindful about my "#include" statements since you can get a "redefinition" error if it gets defined by two functions.

I had my main program (014-xxxx_Rev0_1.ino) including Mux_Setup.h and Ground_Fault_Test.h including Mux_Setup.h.

This was because Ground_Fault_Test calls a function in Mux_Setup.h.

I like the class definition method. It's very clean. I think I will pursue that.

I also liked the template as well.

Thanks for the information. It is very helpful in helping me organize my programs. I'm still not sure on how the ino files became "un-linked", but linking them back up via ".h" is more inline with what I do anyway.

Thank you Romonaga for the examples. This is very good information that I will use in the future.

Your welcome, glad it helped.