Multiple input through Serial monitor

hey guys,
I need to write only two seperate numbers in serial monitor and save them in a vector as element one and two.
I wrote sth but it only takes the first value and it returns zero for second value.

String input;
String input1;
void loop()
{

if(Serial.available()){
input = Serial.readStringUntil('\n');
input1 = Serial.readStringUntil('\n');
SL[0]= input.toFloat();
SL[1]= input1.toFloat();
Serial.print("You typed: " );
Serial.println(SL[0]);
Serial.println(SL[1]);
}
but as I said it only takes the value for input and returns in SL[0] and ignores SL[1].

thx for help. :slight_smile:

Your code is incomplete, and missing code tags

that's all:

String input;
String input1;
float SL[2]={};

void setup() {
Serial.begin(115200);
}

void loop() {

if(Serial.available()){
input = Serial.readStringUntil('\n');
input1 = Serial.readStringUntil('\n');
SL[0]= input.toFloat();
SL[1]= input1.toFloat();
Serial.print("You typed: " );
Serial.println(SL[0]);
Serial.println(SL[1]);
}
}

you are still missing code tags...

  • if you type both values in one line separated by a space then the second one will be ignored
  • if you type them separately and press enter in between but wait for too long then the second read might fail (as you try to read without knowing if there is something to read)
  • of course you need to check that the Serial console is actually sending '\n'...
  • You should probably read Serial Input Basics

Please correct your 2 posts above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)