Added example, added makefile
This commit is contained in:
14
gy521example.c
Normal file
14
gy521example.c
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
14
libgy521.c
14
libgy521.c
@@ -1,7 +1,9 @@
|
|||||||
#include <wiringPi.h>
|
//#include <wiringPi.h>
|
||||||
|
#include <wiringPiI2C.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <libgy521.h>
|
#include <stdlib.h>
|
||||||
|
#include "libgy521.h"
|
||||||
|
|
||||||
//Constants
|
//Constants
|
||||||
|
|
||||||
@@ -19,12 +21,12 @@
|
|||||||
int id;
|
int id;
|
||||||
|
|
||||||
int setupgy521(void) {
|
int setupgy521(void) {
|
||||||
if (id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS) != -1) {
|
if ((id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS)) != -1) {
|
||||||
wiringPiI2CReadReg8(id, MPU6050_PWR_MGMT_1);
|
wiringPiI2CReadReg8(id, MPU6050_PWR_MGMT_1);
|
||||||
wiringPiI2CWriteReg16(id, MPU6050_PWR_MGMT_1, 0);
|
wiringPiI2CWriteReg16(id, MPU6050_PWR_MGMT_1, 0);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return EXIT_FAILURE
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,5 +72,5 @@ float getAngleZ(void) {
|
|||||||
int x = getAccelX();
|
int x = getAccelX();
|
||||||
int y = getAccelY();
|
int y = getAccelY();
|
||||||
int z = getAccelZ();
|
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
20
makefile
Normal 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
|
Reference in New Issue
Block a user