void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available() >= 3)
{
for (int i = 0; i < 4; i++)
{
array[i] = Serial.parseInt();
}
}
if (int i = 0; i < 4; i++)
{
Serial.print(array[i]);
}
}
Because that
duhhh, okk
I havent entered any data, and there is a constant flow of these values. WHY?
Help
What did you expect to see?
first i enter my 3 data in the array
then the data are printed on screen
...and then what?
well its the start for another program where I'll use the set of serial input values as parameters to perform tasks
But the code is in the loop function which, well, loops.
I need to create another void ?
also how can i pass these values to another function ?
They're called "function"s, never "void"s.
You've passed a value to the Serial begin function. It happens to be a literal constant, but it could just as well be a variable.
Ive left the void loop function blank and created another function with the same instructions.
- i didnt get the recurring data
- was able to enter 3 data
- no data were printed so i can say if it is saved or not.
Another question once, the serial input is assigned inside the array. Will it remained the same always. to clear it I need to use the flush command.?
No, flush applies to Serial output
int array[3] = {};
void setup()
{
Serial.begin(9600);
}
void loop()
{
}
void manual()
{
if (Serial.available() >= 3)
{
for (int i = 0; i < 4; i++)
{
array[i] = Serial.parseInt();
}
}
for (int i = 0; i < 4; i++)
{
Serial.print(array[i]);
}
}
Still not working
Here is your code with some added comments
int array[3] = {}; //AN ARRAY WITH **3** ELEMENTS
void setup()
{
Serial.begin(9600);
}
void loop()
{
}
void manual() //THIS FUNCTION IS NEVER CALLED
{
if (Serial.available() >= 3) //MAKE SURE THAT THERE ARE AT LEAST 4 **BYTES** AVAILABLE
{
for (int i = 0; i < 4; i++)
{
array[i] = Serial.parseInt(); //READ **4** **INTS**
}
}
for (int i = 0; i < 4; i++)
{
Serial.print(array[i]);
}
}
- You are trying to put 4 ints into an array with only 3 elements
- You never call the manual() function
- each int takes 2 bytes so you need 8 bytes to be available
He uses parseInt, that analyzes ASCII input, so 8 may not be correct and most likely isn't.
for the 8byts, should i change the size of the array then?
Ive added the missing parts that youve stated, Im getting only zeros now. What to do?
Good point
int array[4]={};
void setup()
{
Serial.begin(9600);
}
void loop()
{ manual ();
}
void manual()
{
if (Serial.available()>=4)
{
for (int i=0; i<4; i++)
{
array[i] = Serial.parseInt();
}
}
for (int i=0; i<4; i++)
{
Serial.print(array[i]);
}
}
only 0 is printed which i didnt input
Apart from any other problems, why are you calling manual() in loop() and why are you unconditionally printing the values in the array whether or not values have been entered ?