SCA3000 triple axis digital interface accelerometer
Diff: SCA3000.cpp
- Revision:
- 1:f5f2e79304fb
- Parent:
- 0:fe041345c169
diff -r fe041345c169 -r f5f2e79304fb SCA3000.cpp
--- a/SCA3000.cpp Sun May 29 14:13:20 2011 +0000
+++ b/SCA3000.cpp Thu Jun 09 14:29:16 2011 +0000
@@ -73,6 +73,12 @@
float SCA3000::getAcceleration(int axis) {
+ return getCounts(axis) * 0.75;
+
+}
+
+int SCA3000::getCounts(int axis){
+
int acceleration = 0;
int axis_lsb = 0;
int axis_msb = 0;
@@ -107,30 +113,22 @@
}
- acceleration = ( axis_msb << 8 | axis_lsb );
-
- return countsToMg(acceleration);
-
-}
-
-float SCA3000::countsToMg(int counts){
-
- float acceleration = 0.0;
-
+ int counts = ( axis_msb << 8 | axis_lsb );
+
//If this looks like nonsense it's because
//the datasheet is completely wrong.
if(counts & 0x8000){
counts = (counts >> 3) & 0x1FFF;
- counts = (~counts & 0x1FFF)+ 1;
- acceleration = counts * -0.75;
+ counts = (~counts & 0x1FFF) + 1;
+ acceleration = counts * -1;
}
else{
counts = (counts >> 3) & 0xFFF;
- acceleration = counts * 0.75;
+ acceleration = counts;
}
return acceleration;
-
+
}
int SCA3000::oneByteRead(int address) {
SCA3000 Digital Accelerometer