Any solution to relate the code to the line number?

Hi,
I put some serial.printer() in the sketch, can relate it to the line number?

/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println("sensorValue at 21");
  delay(1);        // delay in between reads for stability
}

say the line 21 relate to: Serial.println("sensorValue at 21");
and if some thing modified, the line number '21' can relatively change?
Thanks
Adam

Serial.print(F("Problem at line #"));
Serial.println(__LINE__);

Note double underlines

2 Likes

Why is the line number important? You need to read the source code to find out the line number. So just call out the program step:

  Serial.println("sensorValue was obtained");

It's not too hard to read the output and find that in the code. You can even copy the string from the output and then use the find key to locate it in the source.

Or a more generic:

  Serial.println("test print 0001");
1 Like

Thanks.
If I have many Serial.println(), it's easy to have line nubmer there.
I've used Serial.println("test print 0001"); way, still need search if the sketch is large.

BTW the forum software delays some responses, from a particular user's point of view. So the answer before mine was not visible when I posted... not great.

I would have just read that an moved on.

It's amazing.
you are wonderful!
Thank you.

Hi @shanren

FYI

ANSI Standard Predefined Macros

http://www.nacad.ufrj.br/online/intel/Documentation/en_US/compiler_c/main_cls/bldaps_cls/common/bldaps_ansi_macros.htm

Additional Predefined Macros

http://www.nacad.ufrj.br/online/intel/Documentation/en_US/compiler_c/main_cls/bldaps_cls/cppug_ccl/bldaps_macros_lin.htm#bldaps_macros_lin

RV mineirin

It's not a matter of delaying. If you opened the thread any time BEFORE that previous message was posted to the database, by it's author clicking the "REPLY" button, you won't see it until you close the thread, then re-open it. I've VERY rarely, if ever, seen a forum that works any other way. Making everyone's display update instantly would make the entire forum, and the database itself, massively slower, and more bandwidth-intensive.

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