Pages: [1]   Go Down
Author Topic: [SOLVED] Help with "dynamic" statement with string and pin state  (Read 205 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code:
Code:
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.
« Last Edit: February 16, 2014, 01:34:04 pm by bule » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Solved.
Code:
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();
  }
Logged

Pages: [1]   Go Up
Jump to: