Added example, added makefile

This commit is contained in:
2016-09-04 20:58:29 +02:00
parent 9b87fcc68c
commit 84d9a3d3a7
3 changed files with 42 additions and 6 deletions

14
gy521example.c Normal file
View File

@@ -0,0 +1,14 @@
#include <stdio.h>
#include <wiringPi.h>
#include "libgy521.h"
int main(void) {
wiringPiSetup();
setupgy521();
while (1) {
printf("AngleX = %f, AngleY = %f, AngleZ = %f\n", getAngleX(), getAngleY(), getAngleZ());
delay(100);
}
}

View File

@@ -1,7 +1,9 @@
#include <wiringPi.h>
//#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <math.h>
#include <libgy521.h>
#include <stdio.h>
#include <stdlib.h>
#include "libgy521.h"
//Constants
@@ -19,12 +21,12 @@
int id;
int setupgy521(void) {
if (id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS) != -1) {
if ((id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS)) != -1) {
wiringPiI2CReadReg8(id, MPU6050_PWR_MGMT_1);
wiringPiI2CWriteReg16(id, MPU6050_PWR_MGMT_1, 0);
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE
return EXIT_FAILURE;
}
}
@@ -70,5 +72,5 @@ float getAngleZ(void) {
int x = getAccelX();
int y = getAccelY();
int z = getAccelZ();
return atan((sqrt(po(y, 2) + pow(x, 2))) / z) * 180.0 / M_PI;
return atan((sqrt(pow(y, 2) + pow(x, 2))) / z) * 180.0 / M_PI;
}

20
makefile Normal file
View File

@@ -0,0 +1,20 @@
#Infos: http://www.ijon.de/comp/tutorials/makefile.html
VERSION = 1.0
CC = /usr/bin/gcc
CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
LDFLAGS = -lwiringPi -lm
OBJ = gy521example.o libgy521.o
waterpicore: $(OBJ)
$(CC) $(CFLAGS) -o gy521example $(OBJ) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $<
.PHONY: clean
clean:
rm -r *.o