Hello:
I Have acquired the accelerometer of Adafruit adxl345. I would like to implement it in a project to know the inclination of a rod that can vary this inclination. To know this angle with precision should take 50 or 100 readings on the x-axis and the y-axis and then make the mean of these measurements. With Other sensors It is easier To do this process but using Adafruit libraries is more complicated. ¿Could you send me some sample code that realize the average of x measures with the instructions event. acceleration. x, event. acceleration. Y, sensors_event_t event, accel. getEvent (& Event).......?
Sorry for my English but I'm from Spain and I use a translator.
Thanks a lot.
adxl345
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: adxl345
I don't understand the difficulty. The math for calculating the average is the same regardless of what library you use to obtain the readings.With Other sensors It is easier To do this process but using Adafruit libraries is more complicated.
Code: Select all
float x = 0;
float y = 0;
float z = 0;
int sampleCount = 100;
for (int i = 0; i < sampleCount; i++)
{
sensors_event_t event;
accel.getEvent(&event);
x += event.acceleration.x;
y += event.acceleration.y;
z += event.acceleration.z;
}
x /= sampleCount;
y /= sampleCount;
z /= sampleCount;
- Oscarlaborda
- Posts: 2
- Joined: Wed Apr 17, 2019 9:44 am
Re: adxl345
thank you. the one who failed was me who did not know very well where to place the instructions. I thought that some of them would get out of the for. thank you .
Please be positive and constructive with your questions and comments.