#FUSES NOMCLR
#use i2c(Master,Fast, sda=PIN_B0, scl=PIN_B1,force_sw, stream=OLED_stream)//parametros I2C
#use i2c(Master, Fast, sda=PIN_B0, scl=PIN_B1,force_sw, stream=ADXL345_stream)//parametros I2C
#define SH1106_128_64 //DEFINE EL MODELO DE LA PANTALLA OLED
//#define SSD1306_128_64
#include "OLED_I2C.c" //libreria oled I2C
#include "ADXL345.c"
void main()
{
OLED_Begin();
OLED_ClearDisplay();
ADXL345_init();
setRangeSetting(2);// 2g, 4g, 8g, 16g
signed int16 x, y, z;
float gx, gy, gz;
char texto[125];
while(TRUE)
{
readAccel(&x, &y, &z);//Valor de 10bits o 13bits
sprintf(texto,"X: %05ld",x);
OLED_DrawText(1,1,texto,1);
sprintf(texto,"Y: %05ld",y);
OLED_DrawText(1,10,texto,1);
sprintf(texto,"Z: %05ld",z);
OLED_DrawText(1,20,texto,1);
readG(&gx, &gy, &gz);//Valor de Fuerza de gravedad
sprintf(texto,"X: %f",gx);
OLED_DrawText(1,35,texto,1);
sprintf(texto,"Y: %f",gy);
OLED_DrawText(1,45,texto,1);
sprintf(texto,"Z: %f",gz);
OLED_DrawText(1,55,texto,1);
OLED_Display();//Muestra la informacion en la pantalla
}
}