Go Down

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

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.

#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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy