Hello, I am a beginner for using arduino library.
I am doing a project to programme ADXL345 through using arduino.
Now that I have connect ADXL345 to arduino through I2C like the link here.
I would like to set the range, do the offset for different axis through using the self-test function of the ADXL345.
I also find the ADXL345 library from a website.
http://bildr.org/2011/03/adxl345-arduino/
In the library, I have found those programme in the file Adxl345.cpp
For range setting:
// Gets the range setting and return it into rangeSetting
// it can be 2, 4, 8 or 16
void ADXL345::getRangeSetting(byte* rangeSetting) {
byte _b;
readFrom(ADXL345_DATA_FORMAT, 1, &_b);
*rangeSetting = _b & B00000011;
}
// Sets the range setting, possible values are: 2, 4, 8, 16
void ADXL345::setRangeSetting(int val) {
byte _s;
byte _b;
switch (val) {
case 2:
_s = B00000000;
break;
case 4:
_s = B00000001;
break;
case 8:
_s = B00000010;
break;
case 16:
_s = B00000011;
break;
default:
_s = B00000000;
}
readFrom(ADXL345_DATA_FORMAT, 1, &_b);
_s |= (_b & B11101100);
writeTo(ADXL345_DATA_FORMAT, _s);
}
For Self-test:
// gets the state of the SELF_TEST bit
bool ADXL345::getSelfTestBit() {
return getRegisterBit(ADXL345_DATA_FORMAT, 7);
}
// Sets the SELF-TEST bit
// if set to 1 it applies a self-test force to the sensor causing a shift in the output data
// if set to 0 it disables the self-test force
void ADXL345::setSelfTestBit(bool selfTestBit) {
setRegisterBit(ADXL345_DATA_FORMAT, 7, selfTestBit);
}
For offset:
// Sets the OFSX, OFSY and OFSZ bytes
// OFSX, OFSY and OFSZ are user offset adjustments in twos complement format with
// a scale factor of 15,6mg/LSB
// OFSX, OFSY and OFSZ should be comprised between
void ADXL345::setAxisOffset(int x, int y, int z) {
writeTo(ADXL345_OFSX, byte (x));
writeTo(ADXL345_OFSY, byte (y));
writeTo(ADXL345_OFSZ, byte (z));
}
// Gets the OFSX, OFSY and OFSZ bytes
void ADXL345::getAxisOffset(int* x, int* y, int*z) {
byte _b;
readFrom(ADXL345_OFSX, 1, &_b);
*x = int (_b);
readFrom(ADXL345_OFSY, 1, &_b);
*y = int (_b);
readFrom(ADXL345_OFSZ, 1, &_b);
*z = int (_b);
}
Now that I can not call those funcion from the library.
I would like to ask how to call the library in the Arduino programme.
Do anyone have this ADXL345 programming experience??
Thank You=]