Pregunta

i wrote simple arduino program to check a an array of ascii characters. Here is the program

void setup(){
  Serial.begin(9600); // connect serial

}

void loop(){

char inByte;
  char arr[100]={0};
  char arrr[5]={'s','t','a','r','t'};
 int x=0;
 int y=0;
  do{

    arr[x]=arrr[y];
    x++;
    y++;
      }while(arr[0]!='s' && arr[1] !='t' && arr[2]!='a' && arr[3]!='r' && arr[4]!='t');
  if(arr[0]=='s' && arr[1] =='t' && arr[2]=='a' && arr[3]=='r' && arr[4]=='t'){
    delay(1000);
    Serial.println("done");}
    else{
    delay(1000);
    Serial.println("oo");
}

}

I want it to show "done" in serial monitor but instead it is printing "oo"..can any one tell me what is the problem in the program..thanks

No hay solución correcta

Otros consejos

open braces for else part also

if(arr[0]=='s' & arr[1] =='t' & arr[2]=='a' & arr[3]=='r' & arr[4]=='t'){
    delay(1000);
    Serial.println("done");
}
else {
    delay(1000);
    Serial.println("oo"); 
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top