Understanding Serial.read()


hey guys,

i trying send string via serial monitor arduino , got stuck in there somehow.

my question is: there difference between creating list of chars manually or receiving chars serial input?

as example:

code: [select]

char str1[] = {"hello"};

and

code: [select]

void loop(void) {

 char str[5];
 if (serial.available()>0){
  int index = 0;

  while (serial.available()>0){
   char tmp = (char)serial.read();
   str[index] = tmp;
   index++;
  }
 str[index] = '\0';
 }
}


now, if send 'hello' (without ' ') via serial monitor arduino, shouldn't 'str1' , 'str' identically same?

is there difference between both of them memory-wise? feel missing in there.

hopefully of can me, appreciate :smiley-sad:

thank guys much,

tobi

code: [select]
while (serial.available()>0){how long expect condition true?
so why set array index 0 in loop?


have @ robin2's serial handling basics thread.


Arduino Forum > Using Arduino > Programming Questions > Understanding Serial.read()


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts