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?
-
... ... What ... ... ?Majenko– Majenko2017年07月08日 09:01:45 +00:00Commented 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– Jot2017年07月09日 11:19:37 +00:00Commented 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– JRobert2018年10月01日 19:39:56 +00:00Commented Oct 1, 2018 at 19:39
-
@JRobert, the Answer by Jot is good. The Question should be edited.Juraj– Juraj ♦2018年10月02日 09:27:43 +00:00Commented Oct 2, 2018 at 9:27
1 Answer 1
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.
-
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– Lance2017年07月09日 11:13:42 +00:00Commented Jul 9, 2017 at 11:13
-
1The link to main.cpp has moved to a new repository, here is the new location.Luke Bayes– Luke Bayes2018年10月01日 14:37:57 +00:00Commented 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– Jot2018年10月01日 16:04:38 +00:00Commented Oct 1, 2018 at 16:04