Is there a default var that contains current filename of sketch ?

Is there a default var that contains current filename of sketch ?
Long time Arduino guy here.
I wish to print out the sketch filename of current sketch so in future
I can tell the source code of what is loaded during runtime.
regards
Mike

__FILE__ is worth looking into.

void setup() {
   while( !Serial && millis() < 5000 );
   Serial.begin(115200);
   Serial.println(__FILE__);
}

void loop() {
}
Monitor port settings:
baudrate=115200
Connected to /dev/ttyUSB1! Press CTRL-C to exit.
/home/me/Documents/sketchbook/Uno_R3/test/test.ino

This works, thanks a lot.
I saw this while searching, but I did not understand it.

That is a string that is saved by the compiler. it is not placed in your code unless you use the "FILE" variable. There are many others as well.

Is there a list of the compiler variables ?

You might start here:

Predefined Macros, GNU

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.