Read float array from serial monitor

Hello,

Sorry if this subject already was discussed but cannot find proper code. I need example how to read 10 float numbers from serial monitor and store it in array.

Thanks

I would suggest to study Serial Input Basics to handle this

1 Like
float arr[10];

for (int i=0; i<10; i++)
{
   arr[i] = Serial.parseFloat();
}

Put all 10 numbers on one line, seperated by any non-number characters like spaces, commas, letters...

1 Like

parserFloat() does not handle invalid data well, it just returns 0 for 'abc' etc
If you want something better you can use the
SafeString toFloat() method

See SafeString conversions in my Arduino Software Solutions
which also covers various ways to read of the numbers in.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.