Salve a tutti. Sto lavorando al mio primo progetto in Arduino, quindi chiedo scusa in anticipo se la domanda può risultare sciocca.
Sto cercando di mettere dei dati presi da un accelerometro (l'LSM303DLH) in un array. Quello che vorrei ottenere è che dopo un certo numero di dati salvati, Arduino mandi l'array di dati sulla porta seriale per mostrarli.
Questo è il codice di partenza.
/*
The sensor outputs provided by the library are the raw 16-bit values
obtained by concatenating the 8-bit high and low accelerometer and
magnetometer data registers. They can be converted to units of g and
gauss using the conversion factors specified in the datasheet for your
particular device and full scale setting (gain).
Example: An LSM303D gives a magnetometer X axis reading of 1982 with
its default full scale setting of +/- 4 gauss. The M_GN specification
in the LSM303D datasheet (page 10) states a conversion factor of 0.160
mgauss/LSB (least significant bit) at this FS setting, so the raw
reading of -1982 corresponds to 1982 * 0.160 = 317.1 mgauss =
0.3171 gauss.
In the LSM303DLHC, LSM303DLM, and LSM303DLH, the acceleration data
registers actually contain a left-aligned 12-bit number, so the lowest
4 bits are always 0, and the values should be shifted right by 4 bits
(divided by 16) to be consistent with the conversion factors specified
in the datasheets.
Example: An LSM303DLH gives an accelerometer Z axis reading of -16144
with its default full scale setting of +/- 2 g. Dropping the lowest 4
bits gives a 12-bit raw value of -1009. The LA_So specification in the
LSM303DLH datasheet (page 11) states a conversion factor of 1 mg/digit
at this FS setting, so the value of -1009 corresponds to -1009 * 1 =
1009 mg = 1.009 g.
*/
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
char report[80];
void setup()
{
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
}
void loop()
{
compass.read();
snprintf(report, sizeof(report), "A: %6d %6d %6d M: %6d %6d %6d",
compass.a.x, compass.a.y, compass.a.z,
compass.m.x, compass.m.y, compass.m.z);
Serial.println(report);
delay(100);
}
Stavo pensando di mettere un contatore e un ciclo if (se la lettura è minore del numero di dati che voglio continua a prendere dati, altrimenti manda l'array di dati alla seriale per mostrarli.) Il problema è che non so davvero come fare visto che come ho già detto sono un novellino in materia.
Grazie in anticipo a tutti coloro che mi possono/vogliono aiutare.