Hi guys, Im having problems storing arrays of data from the serial input of the arduino, I made a program to read the data and print back the array ordered but it does not seem to work.
It prints this.
I recived: 1-0-0-0-0-0-0-0-
I recived: 2-0-0-0-0-0-0-0-
I recived: 3-0-0-0-0-0-0-0-
When it should be printing this.
I recived: 1-2-3-0-0-0-0-0-
Can anyone tell me where Im wrong?
Here is the code, the program reads it ok just does not store it correctly.
int d[8];
int b = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
b = 0;
for(b = 0; b < 8; b++) {
d[b] = 0;
}
b = 0;
while(Serial.available() > 0) { //Verifies serial byte ready
Serial.println(""); //New line
Serial.print("I recived: "); //Prints the start mesage
for (b = 0; b < 8; b++) { //Increase array location
while(Serial.available() > 0) { //Verifies serial byte ready
d[b] = Serial.read() - 48; //Stores data on array location
}
Serial.print(d[b]); //Prints data array location
Serial.print("-"); //Separator
}
}
}
