Go Down

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


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. :(


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]


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?


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131