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
}

2
accelerometer.h Normal file
View File

@@ -0,0 +1,2 @@
void setupAccelerometer(void);
float getaccelerometerdata(void);

View File

@@ -4,7 +4,7 @@ CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
LDFLAGS = -lwiringPi -lpthread LDFLAGS = -lwiringPi -lpthread
OBJ = main.o player.o OBJ = main.o player.o accelerometer.o
pi2ezoplayer: $(OBJ) pi2ezoplayer: $(OBJ)
$(CC) $(CFLAGS) -o pi2ezoplayer $(OBJ) $(LDFLAGS) $(CC) $(CFLAGS) -o pi2ezoplayer $(OBJ) $(LDFLAGS)