Changing 1 & 0 to On and Off

Hi All,

Can someone please explain to me how to change 1 & 0 to On and Off.

What im doing is digitally reading an input and then using a Sim900A module to sms the status to me.

but whats happening now is im recieving the following:

Input 1 is: 0

or

Input 1 is: 1

but what i Want is:

Input 1 is: Off

or

Input 1 is: On

Here is a Sample of my code.

#include <SoftwareSerial.h>
SoftwareSerial Sim900A(9, 10);

int input1 = 11;
int status1 = 0;

String msg;

void setup()
{
 pinMode(input1, INPUT_PULLUP);

 Sim900A.begin(9600);

 Sim900A.println("AT+CMGDA=\""); 
 Sim900A.println("DEL ALL\"");
 delay(500);
 Sim900A.println("AT+CMGF=1");
 delay(500);

void loop()
{

 status1 = digitalRead(input1);

 Sim900A.available()>0;
 Sim900A.println("AT+CNMI=2,2,0,0,0");
 msg = Sim900A.readString();

 if (status1 == LOW)
 {
 Sim900A.println("AT+CMGS=\"+27xxxxxxxxx\"\r"); //xxxxxxxxx is my cell number
 delay(500);
 Sim900A.println(String("Input 1 Is: ") + String(status1));
 delay(500);
 Sim900A.println((char)26);
 delay(100);
 Sim900A.println("AT+CMGDA=\""); 
 Sim900A.println("DEL ALL\",0 ");
 delay(500);
 }

Please someone help!!!

  Sim900A.print("Input 1 Is: ");
  if (status1 == 1) {
    Sim900A.println("On");
  }
  else {
    Sim900A.println("Off");
  }

Or more concise but less beginner friendly by using the ternary operator:

  Sim900A.print("Input 1 Is: ");
  Sim900A.println(status1 == 1 ? "On" : "Off");

Put the words you want to print in an array of chars and use the value returned to display the text using the value as the array index.

char * names[] = {"off", "on"};

void setup()
{
  Serial.begin(115200);
  Serial.println(names[0]);
  Serial.println(names[1]);
}

void loop()
{
}

Note the use of C strings rather than Strings

Thank You so much!!

This one works perfectly!

There is only one question that i have, and that is only to understand what i have written:

This part means:

Sim900A.print("Input 1 Is: ");
  Sim900A.println(status1 == 1 ? "On" : "Off");

[code]

that if status1 is equals to 1 then its on. of it equals to 0 then its off.

if i write it like this:

[code]

Sim900A.print("Input 1 Is: ");
  Sim900A.println(status1 == 0 ? "On" : "Off");

[code]

then it means that 0 = to on and 1 = to off??

thanks again!

SlevenCalevra:
This part means:

Sim900A.print("Input 1 Is: ");

Sim900A.println(status1 == 1 ? "On" : "Off");



that if status1 is equals to 1 then its on. of it equals to 0 then its off.

Yes, that's what it will print. It's functionally the exact same code as this:

pert:

Sim900A.print("Input 1 Is: ");

if (status1 == 1) {
  Sim900A.println("On");
}
else {
  Sim900A.println("Off");
}

Only written in a different way, that takes less typing but is also harder to read.

SlevenCalevra:
if i write it like this:

Sim900A.print("Input 1 Is: ");

Sim900A.println(status1 == 0 ? "On" : "Off");



then it means that 0 = to on and 1 = to off??

Give it a try.