The one thing that does not work reliably is function prototypes.
So I want to organise my stuff in multiple inos
MultipleIno2.01.cpp is the main sketch file and contains all variables, definitions and so on
struct POSITION
{
int x;
int y;
};
POSITION pos = {0, 0};
and separate files for setup(), loop() and the functions.
a_setup.ino
void setup()
{
Serial.begin(115200);
while (!Serial) {}
// CORRECTION; thanks @ptillisch
// printPos(pos);
printPosition(pos);
}
b_loop.ino
void loop()
{
// put your main code here, to run repeatedly:
}
c_functions.ino contains all functions
void printPosition(POSITION p)
{
Serial.print(F("p.x = "));
Serial.println(p.x);
Serial.print(F("p.y = "));
Serial.println(p.y);
}
Below is the (corrected) file that is created by the Arduino builder
#include <Arduino.h>
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\a_setup.ino"
void setup();
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\b_loop.ino"
void loop();
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\c_functions.ino"
void printPosition(POSITION p);
#line 0 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\a_setup.ino"
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\MultipleIno2.0.1.ino"
// C:\Users\Wim\AppData\Local\Temp\arduino\sketches\4C00CB8A892D58E1DEFAE9736B98376F
struct POSITION
{
int x;
int y;
};
POSITION pos = {0, 0};
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\a_setup.ino"
void setup()
{
Serial.begin(115200);
while (!Serial) {}
printPosition(pos);
}
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\b_loop.ino"
void loop()
{
// put your main code here, to run repeatedly:
}
#line 1 "C:\\Users\\Wim\\Documents\\Arduino\\Forums\\_DemoCode\\MultipleIno2\\MultipleIno2.0.1\\c_functions.ino"
void printPosition(POSITION p)
{
Serial.print(F("p.x = "));
Serial.println(p.x);
Serial.print(F("p.y = "));
Serial.println(p.y);
}
And if that is compiled you will get errors; as a newbie I will probably throw the towel in the ring and work with one massive ino file. This is a known issue for years and still has not been resolved (I don't say that it will be easy to resolve).
Another problem for newbies can be that if there is an error in one of the ino files, the compiler might very well complain about another ino file that was not modified.
Not related to multiple inos but a similar problem: Incorrect placement of auto-generated prototypes gives misleading error messages · Issue #362 · arduino/arduino-builder · GitHub. That was with IDE 1.8.13, just tested it with IDE 2.0.1 and the issue is still there.
Note:
personally I use .h and .cpp files but to make things easier for difficult customers I sometimes use multiple inos and it bites me every time.