Serial.println() on its own with no value?

Hi,
I was just working my way through understanding an example sketch from the Adafruit_VL53L0X library and came across Serial.println() with no value assigned. This can be found in the body of the if statement in the loop function.

/* This example shows how to take
range measurements with the VL53L0X and display on a SSD1306 OLED.

The range readings are in units of mm. */

#include <Wire.h>
#include "Adafruit_VL53L0X.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306();

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

#if (SSD1306_LCDHEIGHT != 32)
 #error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()
{
  Serial.begin(9600);
    
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // init done
  display.display();
  delay(1000);
    
  
  Wire.begin();

  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }

  // text display big!
  display.setTextSize(4);
  display.setTextColor(WHITE);
}

void loop()
{
  VL53L0X_RangingMeasurementData_t measure;

  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
      display.clearDisplay();
      display.setCursor(0,0);
      display.print(measure.RangeMilliMeter);
      display.print("mm");
      display.display();
      Serial.println();
      delay(50);
  } else {
    display.display();
    display.clearDisplay();
    return;
  }
}

Is it purely there so you can add what you like, or is there another purpose for this empty function that I don't know of?
Thanks

Serial.println();

Moves the cursor to the next line by outputting a Carriage Return and a Newline

came across Serial.print() with no value assigned

Where? I cannot see this in the code you provided. The only Serial line is Serial.println() - this prints a new line.

tomdixo:
or is there another purpose for this empty function that I don't know of?

Probably not. The programmer either doesn't know what he is doing and just wants to waste resources and/or paper or, since the nonsense code is the only serial command in the entire loop, the code may be incomplete. Likely to be a bit of both.

The is confusion here between Serial.println(), as in the topic title and the code, and Serial.print() as in the topic text, which I suspect is a typo

Using the former, as in the code, makes sense whereas using the latter would not

For those mentioning the Serial.print() in the original post, it was a typo but I have corrected it now. Sorry and thanks for pointing it out.

I assumed Serial.println(); would just printed a new line and, like you said, as there is no other Serial command apart from the intialisation they might have just carried it over from one of the other example sketches and forgot to take it out or something.

Glad we cleared it up that there isn't some mysterious use for it. Thanks for everyones help.

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