Go Down

Topic: Making selfmade functions includable in other projects. (Read 151 times) previous topic - next topic

Railroader

In my work to control a CNC machine from a sketch running in an UNO with a stepper shield I have developed some useful functions. It would be nice to save the functions, one by one, and include them in other projects. Can You tell me the steps in the proper direction?

jremington

#1
Oct 09, 2018, 04:20 am Last Edit: Oct 09, 2018, 04:40 am by jremington
I "select block" and "cut" or "copy" the function from within the Arduino editor and paste the function text into any other text editor. In Windows, Notepad++ is hard to beat.

Save that to a file with a .c or .cpp extension (for example "function.c").

If it is in the directory with your Arduino .ino file, it will automatically show up in a new tab in the Arduino editor. Include function.c into a new sketch using
Code: [Select]
#include "function.c"

pert

You do this by putting those generally useful functions in a library. Here is a tutorial:
https://www.arduino.cc/en/Hacking/LibraryTutorial
Work through that tutorial and if you get stuck come back and we'll help you out.

Go Up