Changing format of Serial.Println

My code is quite simple.
My goal is to change the Serial output from “Your LED is 0” your “Your LED is 1”, to, “Your LED is Off” “Your LED is On”
I imagine this would be an If statement defining a “High” as a Sting = “On” and “Low” as a String = “Off.”
As simple as it sounds, this info is going to feed a much larger project I’m going to apply the knowledge to.
Can someone educate me on changing the output to a string?
Thanks!

String LED = "Your LED is ";
void setup() {
    Serial.begin (9600);
    pinMode (LED_BUILTIN,OUTPUT);
      }
void loop() {
digitalWrite( LED_BUILTIN, HIGH);
Serial.print (LED);
Serial.println (digitalRead(LED_BUILTIN));

delay (1000);

digitalWrite (LED_BUILTIN, LOW);
Serial.print (LED);
Serial.println (digitalRead(LED_BUILTIN));

delay (1000);
}

if (digitalRead(LED_BUILTIN));
Serial.println ("true");
else
Serial.println ("false");

-jim lee

Before you get into what is often seen the bad habit of using Strings (objects created using the String library) you might like to consider using C style strings (zero terminated arrays of chars) which are generally seen as preferable when using a microcontroller as they do not cause memory fragmentation

char LED[] = "Your LED is ";

void setup()
{
  Serial.begin (115200);
  pinMode (LED_BUILTIN, OUTPUT);
}
void loop()
{
  digitalWrite( LED_BUILTIN, HIGH);
  Serial.print (LED);
  Serial.println (digitalRead(LED_BUILTIN));
  delay (1000);
  digitalWrite (LED_BUILTIN, LOW);
  Serial.print (LED);
  Serial.println (digitalRead(LED_BUILTIN));
  delay (1000);
}

You can also use the ternary operator to embed the test into the print statementSerial.println (digitalRead(LED_BUILTIN) == HIGH ? F("On") : F("Off"));

Thank you all for your assistance!

You can also use the ternary operator to embed the test into the print statement

Bearing in mind the basic question asked I don't think that is a very sensible suggestion to make in the circumstances. A nice, simple if/else will do nicely for now. There is plenty of time to introduce the ternary operator later, if at all, and although the F() macro has its place it is not needed here.

that's the beauty of a free world, we can disagree.

I added my comment as an "also" ==> an alternative to the basic if/else

That's how I would write it and I don't see any difficulty with the ternary operator even for beginners - they seem to get it very easily from my experience and that's a good use case.

I also think we should use the F() macro more in examples to advertise the capability.

jimLee:
if (digitalRead(LED_BUILTIN));
Serial.println (“true”);
else
Serial.println (“false”);

-jim lee

Oops

Uggh! What I get for being in a hurry and coding with copy/paste.

-jim lee