11

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
    Commented Jul 8, 2017 at 9:01
  • No need to put on hold. English is not my native language, and I had no problem with the question.
    – Jot
    Commented Jul 9, 2017 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
    Commented Oct 1, 2018 at 19:39
  • @JRobert, the Answer by Jot is good. The Question should be edited.
    – Juraj
    Commented Oct 2, 2018 at 9:27

1 Answer 1

11

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
    Commented Jul 9, 2017 at 11:13
  • 1
    The link to main.cpp has moved to a new repository, here is the new location.
    – Luke Bayes
    Commented Oct 1, 2018 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
    Commented Oct 1, 2018 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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