Added example, added makefile
This commit is contained in:
14
libgy521.c
14
libgy521.c
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user