8

Is the .ino file an alternative from a main.cpp file?

If yes, then could someone mind explaining the structure of the .ino file in main.cpp and its relationship?

4
  • ... ... What ... ... ? – Majenko Jul 8 '17 at 9:01
  • No need to put on hold. English is not my native language, and I had no problem with the question. – Jot Jul 9 '17 at 11:19
  • As well, closure is usually applied for obviously off-topic questions or worse infractions. Why was this closed rather than just held for clarification? Voting to re-open. – JRobert Oct 1 '18 at 19:39
  • @JRobert, the Answer by Jot is good. The Question should be edited. – Juraj Oct 2 '18 at 9:27
10

The Arduino uses the gcc compiler. That compiler wants a normal main function of course. Arduino has put a layer on top of that with setup and loop.

The hidden main function for basic Arduino boards is in main.cpp (click on it to see it).
You see that init is called, and setup and loop and a few other things.

To learn how to use setup and loop, you can try a few examples. They are in the menu of the Arduino IDE and they are also online.

The .ino files are all combined together and presented to the compiler as a single .cpp file to compile. The Arduino libraries are compiled from source as well, and everything is linked into a binary.

When you know how to use setup and loop, try the Blink Without Delay example. It can be used to run different software timers and do all kind of tasks and keep everything running smooth.

3
  • It solves my query, thanks for explaining the int main function in main.cpp. Also I would try the blink w/o delay example as you suggested. – Lance Jul 9 '17 at 11:13
  • 1
    The link to main.cpp has moved to a new repository, here is the new location. – Luke Bayes Oct 1 '18 at 14:37
  • 1
    @LukeBayes Thanks, I have adjusted the link in my answer. The old standard avr has been moved to "ArduinoCore-avr". – Jot Oct 1 '18 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.