00001 /* AccelMMA7361.h - Library for retrieving data from the MMA7361 accelerometer. 00002 00003 Private Variables: 00004 -int zPin: which pin the z-axis pin is connected to. ANALOG IN 00005 -int gSelectPin: which pin the Gselect is connected to. Unconnected. 00006 -int sleepPin: which pin the sleep port is attached. DIGITAL OUT 00007 -int selfTestPin: which pin the selftest port is attached. Unconnected. 00008 -int zeroGPin: which pin the ZeroGpin is connected to. DIGITAL IN 00009 -double refV: The reference voltage 00010 -int sleeping: Indicates whether or not the accelerometer is in sleep mode (0 is not sleeping, 1 is sleeping) 00011 -int lowGrav: 1 indicates 1.5g mode, 0 indicates 6g mode 00012 -float acceleration[2]: [{old accel},{new accel}] 00013 -float velocity[2]: [{old velocity},{new velocity}] 00014 -float displacement[2]: [{old displacement},{new displacement}] 00015 00016 Functions currently present: 00017 -void init(pin arguments): Initializes all the relevant pins 00018 -void sleep(): Lets the accelerometer enter sleep mode 00019 -void setAREF(double refV): Sets reference voltage to the value 00020 -void calibrate(): Removes the offset from the raw data 00021 00022 -int getRawData(): Returns the raw data from the Z-axis analog I/O port of the Arduino as a int. OFFSET HAS NO INFLUENCE. 00023 -int getVoltData() 00024 -float mapToAccel(): Maps raw data to acceleration 00025 00026 -void getData(): Prints acceleration, velocity, and displacement to UART while implementing 00027 subfunctions such as an acceleration filter, averaging, and end of movement detection 00028 -void setPeriod(): Input period in int ms, output period in float seconds 00029 -void setTolerance(): Sets the threshold of the high pass filter used in getAcceleration 00030 -void isMoving(): A movement 00031 00032 */ 00033 00034 #ifndef AccelMMA7361_h 00035 #define AccelMMA7361_h 00036 #include "Arduino.h" 00037 00038 class AccelMMA7361 00039 { 00040 public: 00041 AccelMMA7361(); 00042 void init(int zPin, int sleepPin, int zeroGPin); 00043 void sleepToggle(int sleep); 00044 void setAREF(float refV); 00045 int calibrate(); 00046 00047 int getRawData(); 00048 int getVoltData(); 00049 float mapToAccel(int raw); 00050 00051 void getData(unsigned int smp); 00052 void getDisplacement(); 00053 void setTolerance(float limit); 00054 void isMoving(); 00055 void resetData(); 00056 00057 float acceleration[2]; 00058 float velocity[2]; 00059 float displacement[2]; 00060 float period; 00061 unsigned int acceliszero; 00062 00063 private: 00064 int zPin; 00065 int sleepPin; 00066 int zeroGPin; 00067 float refV; 00068 int sleeping; 00069 int lowGrav; 00070 int zOffset; 00071 float threshold; 00072 }; 00073 00074 #endif