Pages: [1]   Go Down
Author Topic: Can you link in source code from other sketches?  (Read 550 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
You played your cards but you couldn't win....ED-I-SON'S MEDICINE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is definitely a newb question, but is it possible to link source code from another sketch?

For example, I could have some fully debugged function code that I'd like to include in a sketch, but instead of cut/pasting it into the sketch I'm working on, I'd like to just include a reference link (#include?) to it.  That'd keep my sketch easier to work on and debug.  I do that kind of stuff all the time in the language I'm used to working in (Clarion...I know, you probably never heard of it smiley-razz)

Do you have to create a library or something or can you just include uncompiled source code?

Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you have to create a library or something or can you just include uncompiled source code?

Creating a library is one way. You can't include a .pde file, you can however open tabbed windows in the IDE and paste in .c or .cpp functions and then include them in your main sketch. However best to listen to the software experts that hang around here for gory details, as I only act as a programmer around here.  smiley-wink
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have two options. Like retrolefty said, you can open a new tab and paste in the code. Or, as you said, you can create a library and #include it.

To create a library, navigate to your Arduino Sketchbook. If there is not already a folder called Libraries, create one there. Then create a new folder for your library. Plop all the source files in there, including at least one header file.

This last step is crucial. Just when you think you're done, you also have to create an Examples folder inside your library's folder, whether or not you actually write any examples in it. The IDE will not consider your folder a library without the Examples folder.

You must also restart your Arduino environment before Arduino will recognize the library.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This last step is crucial. Just when you think you're done, you also have to create an Examples folder inside your library's folder, whether or not you actually write any examples in it. The IDE will not consider your folder a library without the Examples folder.

I was ignorant of the Examples folder requirement. Yet I seem to have created libraries that work OK.
???
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, I had to do it.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This last step is crucial. Just when you think you're done, you also have to create an Examples folder inside your library's folder, whether or not you actually write any examples in it. The IDE will not consider your folder a library without the Examples folder.

I was ignorant of the Examples folder requirement. Yet I seem to have created libraries that work OK.
???

Looking at the contents of my libraries folder, about 12 entries, none that I wrote, about 3 of them don't have a example folder. I would be very surprised if that is a requirement, it just doesn't make any sense that it would be.

Lefty
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
You played your cards but you couldn't win....ED-I-SON'S MEDICINE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the replies
Logged

Pages: [1]   Go Up
Jump to: