Go Down

Topic: Serial printing some weird value (Read 289 times) previous topic - next topic

rahulkp1986

i have this code .. after every 10 cycles its serialprinting some unknown value can some one help
Code: [Select]
"char* myStrings[]={"ON","OFF","ON","TRIP","ON","OFF","CLOSE","OFF","ON","OPEN"};
int a,b,c,d,e,f,g,h,i=0,j,k,l,p,m;
void setup(){
Serial.begin(115200);
}

void loop(){

  if (i==10)
{
  i=0;
}
else {
  i++;
  a=i;
  b=-2.2*i;
  c=3.3*i;
  d=4.4*i;
  e=-5.5*i;
  f=6.6*i;
  g=7.7*i;
  h=i*8.8;
  j=i*9.9;
  k=i*10.6;
  l=i*-11.5;
  m=i*1.9;
  }

Serial.print("%S01");
Serial.print(myStrings[i]);
Serial.print(",");
Serial.print("S02");
Serial.print(a);
Serial.print(",");
Serial.print("S03");
Serial.print(c);
Serial.print(",");
Serial.print("S04");
Serial.print(d);
Serial.print(",");
Serial.print("S05");
Serial.print(e);
Serial.print(",");
Serial.print("S06");
Serial.print(f);
Serial.print(",");
Serial.print("S07");
Serial.print(g);
Serial.print(",");
Serial.print("S08");
Serial.print(h);
Serial.print(",");
Serial.print("S09");
Serial.print(a);
Serial.print(",");
Serial.print("S10");
Serial.print(j);
Serial.print(",");
Serial.print("S11");
Serial.print(k);
Serial.print(",");
Serial.print("S12");
Serial.print(l);
Serial.print(",");
Serial.print("S13");
Serial.print(l);
Serial.print(",");
Serial.print("S14");
Serial.print(m);
Serial.print(",");
Serial.print("S15");
Serial.print(a);
Serial.print(",");
Serial.print("S16");
Serial.print(b);
Serial.print(",");
Serial.print("S17");
Serial.print(c);
Serial.print(",");
Serial.print("S18");
Serial.print(d);
Serial.print(",");
Serial.print("S19");
Serial.print(e);
Serial.print(",");
Serial.print("S20");
Serial.print(f);
Serial.print(",");
Serial.print("S21");
Serial.print(g);
Serial.print(",");
Serial.print("S22");
Serial.print(h);
Serial.print(",");
Serial.print("S23");
Serial.print(i);
Serial.print(",");
Serial.print("S24");
Serial.print(j);
Serial.print(",");
Serial.print("S25");
Serial.print(a);
Serial.println("$");
Serial.println("");
delay(300);

}

ieee488

Code: [Select]

loop(){


  a=i;
  b=-2.2*i;
  c=3.3*i;
  d=4.4*i;
  e=-5.5*i;
  f=6.6*i;
  g=7.7*i;
  h=i*8.8;
  j=i*9.9;
  k=i*10.6;
  l=i*-11.5;
  m=i*1.9;


Serial.print("%S01");
Serial.print(myStrings[i]);
Serial.print(",");
Serial.print("S02");
Serial.print(a);
Serial.print(",");
Serial.print("S03");
Serial.print(c);
Serial.print(",");
Serial.print("S04");
Serial.print(d);
Serial.print(",");
Serial.print("S05");
Serial.print(e);
Serial.print(",");
Serial.print("S06");
Serial.print(f);
Serial.print(",");
Serial.print("S07");
Serial.print(g);
Serial.print(",");
Serial.print("S08");
Serial.print(h);
Serial.print(",");
Serial.print("S09");
Serial.print(a);
Serial.print(",");
Serial.print("S10");
Serial.print(j);
Serial.print(",");
Serial.print("S11");
Serial.print(k);
Serial.print(",");
Serial.print("S12");
Serial.print(l);
Serial.print(",");
Serial.print("S13");
Serial.print(l);
Serial.print(",");
Serial.print("S14");
Serial.print(m);
Serial.print(",");
Serial.print("S15");
Serial.print(a);
Serial.print(",");
Serial.print("S16");
Serial.print(b);
Serial.print(",");
Serial.print("S17");
Serial.print(c);
Serial.print(",");
Serial.print("S18");
Serial.print(d);
Serial.print(",");
Serial.print("S19");
Serial.print(e);
Serial.print(",");
Serial.print("S20");
Serial.print(f);
Serial.print(",");
Serial.print("S21");
Serial.print(g);
Serial.print(",");
Serial.print("S22");
Serial.print(h);
Serial.print(",");
Serial.print("S23");
Serial.print(i);
Serial.print(",");
Serial.print("S24");
Serial.print(j);
Serial.print(",");
Serial.print("S25");
Serial.print(a);
Serial.println("$");
Serial.println("");
delay(300);

i++;
if (i == 10)
    i = 0;



rahulkp1986

WORKING GREAT!!!! :)

CAN YOU EXPLAIN WHAT WAS THE PROBLEM?

ieee488

WORKING GREAT!!!! :)

CAN YOU EXPLAIN WHAT WAS THE PROBLEM?
You are immediately incrementing the variable i in the else portion of the code inside loop()

I hope that helps.





Go Up