have problem with filling array from Serial. So basically, first asking for lenght of array, then should input from keyborad all elements. Problem is that it's not waiting to enter values into Serial and just fill with 0. If will type values right away, it will put them into array.
My question is how to force wait from Arduino till i will input values. Thank You!
boolean fill = false;
int sum = 0;
int lengthOfArray;
void setup()
{
Serial.begin(9600);
Serial.print("Set lenght of array : ");
}
void loop()
{
if(fill == false)
{
if(Serial.available() > 0)
{
lengthOfArray = Serial.parseInt();
Serial.println(lengthOfArray);
int tab[lengthOfArray];
for(int i = 0; i < lengthOfArray; i++)
{
delay(10);
Serial.print("Tab[" + String(i) + "] : ");
tab[i] = Serial.parseInt();
Serial.println(tab[i]);
sum += tab[i];
}
fill = true;
Serial.println("Sum = " + String(sum));
}
}
}