Accelerometer hinzugefügt (ungetestet)

This commit is contained in:
2016-09-11 21:03:08 +02:00
parent bece9fee21
commit 6e78a15640
3 changed files with 28 additions and 1 deletions

25
accelerometer.c Normal file
View File

@@ -0,0 +1,25 @@
#include "accelerometer.h"
#include <libgy521.h>
#include <math.h> //for fabs
void setupAccelerometer(void) {
setupgy521();
}
float getaccelerometerdata(void) {
float xyz[] = {getAccelerometerData('x', 1), getAccelerometerData('y', 1), getAccelerometerData('z', 1)};
float temp;
int i, z;
for (i = 0, i < 3; i++) {
for (z = 0; z < 3 - i; z++) {
if (xyz[z] < xyz[z + 1]) {
temp = xyz[z];
xyz[z] = xyz[z + 1];
xyz[z + 1] = temp;
}
}
}
return fabs(xyz[0]); //Absolutwert fuer float
}