Go Down

Topic: [SOLVED] Concatenate Array (Read 213 times) previous topic - next topic

AndreasSchnaas

Feb 10, 2014, 10:32 pm Last Edit: Feb 11, 2014, 09:33 am by AndreasSchnaas Reason: 1
Hello everyone.

I have a little problem with my coding. I've managed to read the axis from an accelerometer. I'd like to have the values printed in the serial port in the following form "x axis, y axis, z axis". At the moment it's printing the values of the 3 axis continuosly. I'm sure I'm missing something in coding.

Code: [Select]


#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

int x [1000];

int y [1000];

int z [1000];

char report[80];

void setup()
{
 Serial.begin(9600);
 Wire.begin();
 compass.init();
 compass.enableDefault();
}

void loop()
{
 int i;
 
for (i=0; i<1000; i = i + 1){

compass.read();

x[i] = compass.a.x;

y[i] = compass.a.y;

z[i] = compass.a.z;

}  


for (i=0; i<1000; i = i + 1){    
 Serial.println(x[i]);
 Serial.println(y[i]);
 Serial.println(z[i]);
}
 delay(10000);
}


As it can be seen, I've made 3 different arrays that read 1000 values from the different axis of the accelerometer and I've tried to print the results onto the serial. The datas are in ASCII characters.

Thanks on advance of any help.

AWOL

#1
Feb 10, 2014, 10:36 pm Last Edit: Feb 10, 2014, 10:38 pm by AWOL Reason: 1
Code: [Select]
for (i=0; i<1000; i = i + 1){   
  Serial.print(x[i]);
  Serial.print(",");
  Serial.print(y[i]);
  Serial.print(",");
  Serial.println(z[i]);
}
Quote
I've made 3 different arrays that read 1000 values

Let's hope you've got a Mega.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AndreasSchnaas

#2
Feb 11, 2014, 09:28 am Last Edit: Feb 11, 2014, 09:33 am by AndreasSchnaas Reason: 1
Thank you very much for your help, it works perfectly.

And yes, I have an Arduino Mega board.

Go Up