Go Down

Topic: making .cpp and .h files (Read 2227 times) previous topic - next topic

kunkmiester

While the Morse example shows the code and how it works, I found it lacking in creation of the actual files--.cpp first, or can the .h be done first?  The mechanics of actually doing this in the IDE aren't really there either, and this isn't obvious when you're looking at the menus and such.  I'm also guessing that these should compile(to verify the code) without being attached to a program?  That's what my logic tells me.

While I've been programming, this is a new IDE.  Browsing the forum here has helped, but not on this point.  The library tutorial kind of starts a bit after this point.

It's the simple things that kill me. :(

PaulS

Use a text editor, other than the Arduino IDE to create the .h and .cpp files. Save them in the same folder as the sketch, and the next time the IDE opens that sketch it will open all the other files in that folder in separate tabs.

Generally, the .h file is created first, since it defines what needs to be coded in the .cpp file.

Coding Badly


Try this...

  • Start the IDE
  • Locate the square with a right-pointing arrow on the top-right of the window.  It's directly across from the tabs.
  • Click the "button"; a pop-up menu should appear
  • Click [New Tab]
  • Enter a filename (e.g. "MyHeader.h") then click [OK]

kunkmiester

So how do I tell it it's a header, and should be checked as such, instead of complaining about the loop and setup functions when verifying?

PaulS

The compiler knows how to handle .h files, .cpp files, and .pde files. So, you simply need to assign the correct extension.

Go Up