55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
// This example use I2C.
|
|
#include "LIS3DHTR.h"
|
|
#include <Wire.h>
|
|
LIS3DHTR<TwoWire> LIS; //IIC
|
|
#define WIRE Wire
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
while (!Serial)
|
|
{
|
|
};
|
|
LIS.begin(WIRE); //IIC init dafault :0x18
|
|
//LIS.begin(WIRE, 0x19); //IIC init
|
|
LIS.openTemp(); //If ADC3 is used, the temperature detection needs to be turned off.
|
|
// LIS.closeTemp();//default
|
|
delay(100);
|
|
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
|
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
|
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
|
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
|
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
|
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
|
LIS.setHighSolution(true); //High solution enable
|
|
}
|
|
void loop()
|
|
{
|
|
if (!LIS)
|
|
{
|
|
Serial.println("LIS3DHTR didn't connect.");
|
|
while (1)
|
|
;
|
|
return;
|
|
}
|
|
//3 axis
|
|
// Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
|
|
// Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
|
|
// Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
|
|
//ADC
|
|
// Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
|
|
// Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
|
|
// Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
|
|
|
|
//temperature
|
|
Serial.print("temp:");
|
|
Serial.println(LIS.getTemperature());
|
|
delay(500);
|
|
}
|