Pages: [1]   Go Down
Author Topic: [SOLVED] Concatenate Array  (Read 171 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

#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.
« Last Edit: February 11, 2014, 03:33:25 am by AndreasSchnaas » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26274
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
« Last Edit: February 10, 2014, 04:38:50 pm by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for your help, it works perfectly.

And yes, I have an Arduino Mega board.
« Last Edit: February 11, 2014, 03:33:54 am by AndreasSchnaas » Logged

Pages: [1]   Go Up
Jump to: