All of the source code is available to you. The only trick is finding it. That depends on your board, for one thing. Code for ARM boards is different from that for AVR boards.
On my system, the IDE is installed in C:\Users\PaulS\Documents\arduino-, and pinMode() is declared in hardware\arduino\avr\cores\arduino\Arduino.h (relative to the install path) and implemented in wiring_digital.c in the same directory.
I wondered about the same stuffwhen I started working with Arduino after writing C for other platforms in other environments for years. Turns out that the Arduino IDE (to the extent that it is an IDE) tries to be “helpful” by doing a lot of #includes (and other stuff) behind the scenes. Others on the board can explain it in much more detail than I.
BTW, I still don’t like it since I really prefer to know where things are coming from. But that’s the way it is.
@whalers1988,
Yep, a lot goes on in the background.
If you start with main.cpp, you will see the function main(), which calls a couple things that only occur once to set up timers and interrupts and such, then setup() once, and then loop() in a never-ending for-loop:
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
So your sketch will contain a few section that will get compiled (pin assignments, global variables, library usages, and setup() and loop() and any other functions that you may use.
As noted, you have all the files called out, you just need to find them as .cpp or .h files, it can be confusing with files calling out other files, like a wild goose chase at times.
On my PC I have them at C:/Arduino_version/hardware/arduino/avr/cores/arduino
where everything after Arduino_version (such as 1.6.5-r5) is the stuff that gets set up when the Arduino files get unzipped.
Oh thank you so much. I hope I can get the hang of this. I am really interested and I like to know everything that is happening from top to bottom. Thanks everyone for your help.
whalers1988:
Where is the code for setup() or pinMode(var1,va2)???
setup() is just the name of the function and you provide all of its code.
The code for pinMode() and the other Arduino-specific functions is included in the files that come with the Arduino IDE. On my PC the code form pinMode() is in the file ..../arduino-1.6.3/hardware/arduino/avr/cores/arduino/wiring_digital.c
Cosme_Fulanito:
I don't really have anything to add to what other have said, except so make a shameless plug...
This is where a proper IDE (like, ehem, Sloeber) comes into play. Your question would have been answered with one Ctrl-Click or F3 press.
I would LOVE to move to a more capable IDE. Started looking through the Sloeber install advice. Ran across this:
“spaces Windows users keep in mind that spaces cause problems. So do not install the arduino IDE eclipse or Sloeber in "program files". Don't create the workspace in "my documents".”