I've been having some issues with something I've never done before, sins I quite expanded my code I divided it to some segment and in those segments(Header files) I wanted to use the global variables from the source file( .ino) in the header files and I dunno what to do.
I'd post the whole code here but it's too long so here's a quick example of what I've done so far.
Edit, example
extern int i; /This declare that i is an int variable which is defined in some other file/
But will it duplicate that variable taking double the space in the micro's memory? or will just define it in the header file to read and write to that variable at the same address?
But will it duplicate that variable taking double the space in the micro's memory?
No. The extern statement says there is a variable with this type and this name, defined somewhere else. It is the linker's job to find where it is defined and substitute the proper address.
I also want to access the libraries and function in the sketch from that header file eventually making in behave like the sketch file but in another file.
I also want to access the libraries and function in the sketch from that header file eventually making in behave like the sketch file but in another file.
Why?
I see that in many programs the code is split to a few sections and in order to make it more organized you need to be able to modify the main sketch variables from other spots through there.
There are two reasons for creating a library. One is just to have a place-holder for related functions. The other is to create a class, modeling some real-life scenario.
Your hand-waving is not telling us which reason you have for creating a library.
Your hand-waving is not telling us what problems you are having with putting a function in a library, and using it from the sketch. Your hand-waving is not telling us what problems you are having defining data in a library and using it in the sketch.
Get someone else to type your next reply. Put your hands in your pockets and communicate using JUST words. We can NOT see your hand-waving.
PaulS:
There are two reasons for creating a library. One is just to have a place-holder for related functions. The other is to create a class, modeling some real-life scenario.
Your hand-waving is not telling us which reason you have for creating a library.
Your hand-waving is not telling us what problems you are having with putting a function in a library, and using it from the sketch. Your hand-waving is not telling us what problems you are having defining data in a library and using it in the sketch.
Get someone else to type your next reply. Put your hands in your pockets and communicate using JUST words. We can NOT see your hand-waving.
All I want is to try to make my main sketch shorter by using a few functions at the header file that can also modify variables in the sketch but when I tried that I figured out that I can't do it neither use functions from the libraries and classes that were declared and included in the main sketch file.
Delta_G:
Sure you can. You must have just done it wrong. Go do it right and it will work.
How do I do it right?
When I try to compile it it says in the header file functions, classes and variable that are being used in there (that refer to what is in there in the sketch file) "was not declared in this scope"
I thought of adding something like #include"Main.ino"
in the top of the header file but it's not possible.
You'd have to fix your code then. Go find the problem in your code and fix it. I can't see your code so I have absolutely zero chance of finding your problem. Do you really think anyone here can fix your code without seeing it?
People are being snarky because:
(1) what you say you want to do is quite possible, but the only way they can diagnose why your code doesn't work is to see it--all of it since tiny mistakes can sometimes have consequences in far distant parts of the code
(2) the stickies at the top of the forum say to post your code--and newbies (and others) rarely do, which has grown tiresome to regulars who have seen this dozens if not hundreds of times.