0

I don't want the same string to be printed again and again. I'm getting the data into an Excel sheet.

byte readValue1=0;
byte readValue2=0;
int add=0;
int row=0;
int Zigbee1=0,Zigbee2=0,Zigbee3=0;
void setup() {
    Serial.begin(9600);
        Serial.println("CLEARDATA");
        Serial.println("LABEL,Time,Zigbee,a1,a2,a3,a4,a5,a6,a7");
        row++;
}

void loop(){
  String a1,a2,a3;
  String c1,c2,c3;
  int b;

  if (Serial.available()>21){
        if(Serial.read() == 0x7E) {  
            for(int i=0; i<10; i++){
                byte discard = Serial.read();
            }
                        add = Serial.read();     
                       if(add == 33)
                        {                 
                        a1 = func1();                    
                        if(a1==c1){
                          b=0;
                        } 
                        else                   
                        {
                          b = a1.length(); 
                        } 
                        if(b != 0)
                       {
                        Zigbee=1;
                        Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                        Serial.print(","); Serial.println(a1);
                        row++;              
                        }
                        }
                      else if(add == 48)
                        { 
                        a2 = func1();
                        b = a2.length();
                        if(b != 0) 
                      { 
                        Zigbee=2;
                        if(a2!=c2){
                       Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                       Serial.print(","); Serial.println(a2);
                        }
                        c2=a2;
                       row++;                                          
                        }
                        }

                       else if(add == 69)
                        {
                          a3 = func1();
                          b = a3.length();
                          if(b != 0)
                         {
                          Zigbee=3;
                          Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                          Serial.print(","); Serial.println(a3);
                          row++;                  
                    }
                        }
} 
}
}
1
  • Can you give sample of the output you are getting and the output you want? Commented Apr 17, 2015 at 3:26

2 Answers 2

0

Only print the string when he has changed?

String previousString = "";
String newString = "";

if(newString != previousString){
   println(newString);
   previousString = newString;
}

I'm not sure if it's applicable in your situation, just the first thing that came to my mind. You (kinda) should make a function of it, so that you don't have to copy/paste it all the time and it'll look way better.

EDIT:

A fuction could be made like so:

String previousString = ""; //Put this above your setup code (global variables)

void NoSpamString(String input){ //Put this block before the setup
   if(input != previousString){
      println(input);
      previousString = input;
   }
}

You can then use: NoSpamString("text"); to print a line withouth spamming it.

5
  • Thanx.. i figured it out.. Commented Apr 22, 2015 at 10:37
  • but i cant make a function coz i need to check the address of every zigbee .. and im not getting how to make a function.. im a newbie.. Commented Apr 22, 2015 at 10:39
  • How did you solve it then? If you believe this answer is the right solution you can use the ✓ on the left side of the answer. Commented Apr 22, 2015 at 13:28
  • No, actually i got the solution later on my own:p Commented Apr 23, 2015 at 10:40
  • You could consider posting the solution you made, as an answer. So that other people who visit this question can use it for their project Commented Apr 23, 2015 at 11:43
0

i solved it out by using comparing the received bits in that frame.. here is my code..

                   if(add == 33)
                    {                 
                    a1 = func1();
                    b = a1.length();  
                    if(b != 0)
                   {
                    Zigbee=1;
                    if(a1!=c1)
                    {
                    Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                    Serial.print(","); Serial.println(a1);
                    }
                    c1=a1;
                    row++;              
                    }
                    }
                  else if(add == 48)
                    { 
                    a2 = func1();
                    b = a2.length();
                    if(b != 0) 
                  { 
                    Zigbee=2;
                    if(a2!=c2){
                   Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                   Serial.print(","); Serial.println(a2);
                    }
                    c2=a2;
                   row++;                                          
                    }
                    }

                   else if(add == 69)
                    {
                      a3 = func1();
                      b = a3.length();
                      if(b != 0)
                     {
                      Zigbee=3;
                      if(a3!=c3)
                     {
                      Serial.print("DATA,TIME,"); Serial.print(Zigbee);                     
                      Serial.print(","); Serial.println(a3);
                     }
                     c3=a3;
                     row++;                  
                }
                    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.