Go Down

Topic: [SOLVED] Help with "dynamic" statement with string and pin state (Read 376 times) previous topic - next topic

bule

Here is my code:
Code: [Select]

else if (txtmsg.compareTo("status") == 0)
 {
    String statustxt = "";
    pinstate = digitalRead(pin);
    if (pinstate == 1){
    sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(statustxt);
    sms.endSMS();
    }
 }

I need to complete the code to do next (my pseudo code)
if txt message is status do next:
if pinstatus == 1
    sting is: relay 'pin' is on
else
string is: relay 'pin' is off
sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(string);
    sms.endSMS();

My brain is stuck, I mean I am stuck at how to create one string with two states.

PaulS

Quote
My brain is stuck, I mean I am stuck at how to create one string with two states.

Probably because that isn't what you want to do. You want to create a string (or String) with one of two different states.

Code: [Select]
char stg[32];
if(i == 27)
   strcpy(stg, "The value really is 27");
else
   strcpy(stg, "The value is not 27");

 

Random
                      indenting
         even in
      psuedo code
                    really isn't
        a good
               idea.

bule

Ok. Thanks for the tip. But when I enter the line
Code: [Select]
sms.print(stg);
What is going to print?

PaulS

Quote
Ok. Thanks for the tip. But when I enter the line ... What is going to print?

Whatever is in stg.

Do not post snippets here and expect much other than smart-assed answers.

bule

Solved.
Code: [Select]

else if (txtmsg.compareTo("status") == 0)
  {
    char stg[32];
    if (digitalRead(pin) == HIGH){
      strcpy(stg, "Relej je ukljucen.");
    }
    else {
      strcpy(stg, "Relej je iskljucen.");
    }
    Serial.println(stg);
    sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(stg);
    sms.endSMS();
  }

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy