elefantasy 12 gadi atpakaļ
revīzija
f1e02add75

+ 22 - 0
.gitattributes

@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs     diff=csharp
+*.sln    merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc	 diff=astextplain
+*.DOC	 diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot  diff=astextplain
+*.DOT  diff=astextplain
+*.pdf  diff=astextplain
+*.PDF	 diff=astextplain
+*.rtf	 diff=astextplain
+*.RTF	 diff=astextplain

+ 215 - 0
.gitignore

@@ -0,0 +1,215 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+#############
+## Windows detritus
+#############
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist/
+build/
+eggs/
+parts/
+var/
+sdist/
+develop-eggs/
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg

+ 635 - 0
DigitalAccelerometer_ADXL345/ADXL345.cpp

@@ -0,0 +1,635 @@
+/*****************************************************************************/
+//	Function:    Cpp file for class ADXL345
+//  Hardware:    3-Axis Digital Accelerometer(¡À16g)
+//	Arduino IDE: Arduino-1.0
+//	Author:	 Frankie.Chu		
+//	Date: 	 Jan 11,2013
+//	Version: v1.0
+//	by www.seeedstudio.com
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License, or (at your option) any later version.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+/*******************************************************************************/
+#include "Arduino.h"
+#include "ADXL345.h"
+#include <Wire.h>
+
+#define ADXL345_DEVICE (0x53)    // ADXL345 device address
+#define ADXL345_TO_READ (6)      // num of bytes we are going to read each time (two bytes for each axis)
+
+ADXL345::ADXL345() {
+	status = ADXL345_OK;
+	error_code = ADXL345_NO_ERROR;
+	
+	gains[0] = 0.00376390;
+	gains[1] = 0.00376009;
+	gains[2] = 0.00349265;
+}
+
+void ADXL345::powerOn() {
+	Wire.begin();        // join i2c bus (address optional for master)
+	//Turning on the ADXL345
+	writeTo(ADXL345_POWER_CTL, 0);      
+	writeTo(ADXL345_POWER_CTL, 16);
+	writeTo(ADXL345_POWER_CTL, 8); 
+}
+
+// Reads the acceleration into three variable x, y and z
+void ADXL345::readAccel(int *xyz){
+	readXYZ(xyz, xyz + 1, xyz + 2);
+}
+void ADXL345::readXYZ(int *x, int *y, int *z) {
+	readFrom(ADXL345_DATAX0, ADXL345_TO_READ, _buff); //read the acceleration data from the ADXL345
+	
+	// each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
+	// thus we are converting both bytes in to one int
+	*x = (((int)_buff[1]) << 8) | _buff[0];   
+	*y = (((int)_buff[3]) << 8) | _buff[2];
+	*z = (((int)_buff[5]) << 8) | _buff[4];
+}
+
+void ADXL345::getAcceleration(double *xyz){
+	int i;
+	int xyz_int[3];
+	readAccel(xyz_int);
+	for(i=0; i<3; i++){
+		xyz[i] = xyz_int[i] * gains[i];
+	}
+}
+// Writes val to address register on device
+void ADXL345::writeTo(byte address, byte val) {
+	Wire.beginTransmission(ADXL345_DEVICE); // start transmission to device 
+	Wire.write(address);             // send register address
+	Wire.write(val);                 // send value to write
+	Wire.endTransmission();         // end transmission
+}
+
+// Reads num bytes starting from address register on device in to _buff array
+void ADXL345::readFrom(byte address, int num, byte _buff[]) {
+	Wire.beginTransmission(ADXL345_DEVICE); // start transmission to device 
+	Wire.write(address);             // sends address to read from
+	Wire.endTransmission();         // end transmission
+	
+	Wire.beginTransmission(ADXL345_DEVICE); // start transmission to device
+	Wire.requestFrom(ADXL345_DEVICE, num);    // request 6 bytes from device
+	
+	int i = 0;
+	while(Wire.available())         // device may send less than requested (abnormal)
+	{ 
+		_buff[i] = Wire.read();    // receive a byte
+		i++;
+	}
+	if(i != num){
+		status = ADXL345_ERROR;
+		error_code = ADXL345_READ_ERROR;
+	}
+	Wire.endTransmission();         // end transmission
+}
+
+// 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);
+}
+// 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);
+}
+
+// Gets the state of the SPI bit
+bool ADXL345::getSpiBit() {
+	return getRegisterBit(ADXL345_DATA_FORMAT, 6);
+}
+
+// Sets the SPI bit
+// if set to 1 it sets the device to 3-wire mode
+// if set to 0 it sets the device to 4-wire SPI mode
+void ADXL345::setSpiBit(bool spiBit) {
+	setRegisterBit(ADXL345_DATA_FORMAT, 6, spiBit);
+}
+
+// Gets the state of the INT_INVERT bit
+bool ADXL345::getInterruptLevelBit() {
+	return getRegisterBit(ADXL345_DATA_FORMAT, 5);
+}
+
+// Sets the INT_INVERT bit
+// if set to 0 sets the interrupts to active high
+// if set to 1 sets the interrupts to active low
+void ADXL345::setInterruptLevelBit(bool interruptLevelBit) {
+	setRegisterBit(ADXL345_DATA_FORMAT, 5, interruptLevelBit);
+}
+
+// Gets the state of the FULL_RES bit
+bool ADXL345::getFullResBit() {
+	return getRegisterBit(ADXL345_DATA_FORMAT, 3);
+}
+
+// Sets the FULL_RES bit
+// if set to 1, the device is in full resolution mode, where the output resolution increases with the
+//   g range set by the range bits to maintain a 4mg/LSB scal factor
+// if set to 0, the device is in 10-bit mode, and the range buts determine the maximum g range
+//   and scale factor
+void ADXL345::setFullResBit(bool fullResBit) {
+	setRegisterBit(ADXL345_DATA_FORMAT, 3, fullResBit);
+}
+
+// Gets the state of the justify bit
+bool ADXL345::getJustifyBit() {
+	return getRegisterBit(ADXL345_DATA_FORMAT, 2);
+}
+
+// Sets the JUSTIFY bit
+// if sets to 1 selects the left justified mode
+// if sets to 0 selects right justified mode with sign extension
+void ADXL345::setJustifyBit(bool justifyBit) {
+	setRegisterBit(ADXL345_DATA_FORMAT, 2, justifyBit);
+}
+
+// Sets the THRESH_TAP byte value
+// it should be between 0 and 255
+// the scale factor is 62.5 mg/LSB
+// A value of 0 may result in undesirable behavior
+void ADXL345::setTapThreshold(int tapThreshold) {
+	tapThreshold = constrain(tapThreshold,0,255);
+	byte _b = byte (tapThreshold);
+	writeTo(ADXL345_THRESH_TAP, _b);  
+}
+
+// Gets the THRESH_TAP byte value
+// return value is comprised between 0 and 255
+// the scale factor is 62.5 mg/LSB
+int ADXL345::getTapThreshold() {
+	byte _b;
+	readFrom(ADXL345_THRESH_TAP, 1, &_b);  
+	return int (_b);
+}
+
+// set/get the gain for each axis in Gs / count
+void ADXL345::setAxisGains(double *_gains){
+	int i;
+	for(i = 0; i < 3; i++){
+		gains[i] = _gains[i];
+	}
+}
+void ADXL345::getAxisGains(double *_gains){
+	int i;
+	for(i = 0; i < 3; i++){
+		_gains[i] = gains[i];
+	}
+}
+
+
+// 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);
+}
+
+// Sets the DUR byte
+// The DUR byte contains an unsigned time value representing the maximum time
+// that an event must be above THRESH_TAP threshold to qualify as a tap event
+// The scale factor is 625µs/LSB
+// A value of 0 disables the tap/double tap funcitons. Max value is 255.
+void ADXL345::setTapDuration(int tapDuration) {
+	tapDuration = constrain(tapDuration,0,255);
+	byte _b = byte (tapDuration);
+	writeTo(ADXL345_DUR, _b);  
+}
+
+// Gets the DUR byte
+int ADXL345::getTapDuration() {
+	byte _b;
+	readFrom(ADXL345_DUR, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the latency (latent register) which contains an unsigned time value
+// representing the wait time from the detection of a tap event to the start
+// of the time window, during which a possible second tap can be detected.
+// The scale factor is 1.25ms/LSB. A value of 0 disables the double tap function.
+// It accepts a maximum value of 255.
+void ADXL345::setDoubleTapLatency(int doubleTapLatency) {
+	byte _b = byte (doubleTapLatency);
+	writeTo(ADXL345_LATENT, _b);  
+}
+
+// Gets the Latent value
+int ADXL345::getDoubleTapLatency() {
+	byte _b;
+	readFrom(ADXL345_LATENT, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the Window register, which contains an unsigned time value representing
+// the amount of time after the expiration of the latency time (Latent register)
+// during which a second valud tap can begin. The scale factor is 1.25ms/LSB. A
+// value of 0 disables the double tap function. The maximum value is 255.
+void ADXL345::setDoubleTapWindow(int doubleTapWindow) {
+	doubleTapWindow = constrain(doubleTapWindow,0,255);
+	byte _b = byte (doubleTapWindow);
+	writeTo(ADXL345_WINDOW, _b);  
+}
+
+// Gets the Window register
+int ADXL345::getDoubleTapWindow() {
+	byte _b;
+	readFrom(ADXL345_WINDOW, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the THRESH_ACT byte which holds the threshold value for detecting activity.
+// The data format is unsigned, so the magnitude of the activity event is compared 
+// with the value is compared with the value in the THRESH_ACT register. The scale
+// factor is 62.5mg/LSB. A value of 0 may result in undesirable behavior if the 
+// activity interrupt is enabled. The maximum value is 255.
+void ADXL345::setActivityThreshold(int activityThreshold) {
+	activityThreshold = constrain(activityThreshold,0,255);
+	byte _b = byte (activityThreshold);
+	writeTo(ADXL345_THRESH_ACT, _b);  
+}
+
+// Gets the THRESH_ACT byte
+int ADXL345::getActivityThreshold() {
+	byte _b;
+	readFrom(ADXL345_THRESH_ACT, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the THRESH_INACT byte which holds the threshold value for detecting inactivity.
+// The data format is unsigned, so the magnitude of the inactivity event is compared 
+// with the value is compared with the value in the THRESH_INACT register. The scale
+// factor is 62.5mg/LSB. A value of 0 may result in undesirable behavior if the 
+// inactivity interrupt is enabled. The maximum value is 255.
+void ADXL345::setInactivityThreshold(int inactivityThreshold) {
+	inactivityThreshold = constrain(inactivityThreshold,0,255);
+	byte _b = byte (inactivityThreshold);
+	writeTo(ADXL345_THRESH_INACT, _b);  
+}
+
+// Gets the THRESH_INACT byte
+int ADXL345::getInactivityThreshold() {
+	byte _b;
+	readFrom(ADXL345_THRESH_INACT, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the TIME_INACT register, which contains an unsigned time value representing the
+// amount of time that acceleration must be less thant the value in the THRESH_INACT
+// register for inactivity to be declared. The scale factor is 1sec/LSB. The value must
+// be between 0 and 255.
+void ADXL345::setTimeInactivity(int timeInactivity) {
+	timeInactivity = constrain(timeInactivity,0,255);
+	byte _b = byte (timeInactivity);
+	writeTo(ADXL345_TIME_INACT, _b);  
+}
+
+// Gets the TIME_INACT register
+int ADXL345::getTimeInactivity() {
+	byte _b;
+	readFrom(ADXL345_TIME_INACT, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the THRESH_FF register which holds the threshold value, in an unsigned format, for
+// free-fall detection. The root-sum-square (RSS) value of all axes is calculated and
+// compared whith the value in THRESH_FF to determine if a free-fall event occured. The 
+// scale factor is 62.5mg/LSB. A value of 0 may result in undesirable behavior if the free-fall
+// interrupt is enabled. The maximum value is 255.
+void ADXL345::setFreeFallThreshold(int freeFallThreshold) {
+	freeFallThreshold = constrain(freeFallThreshold,0,255);
+	byte _b = byte (freeFallThreshold);
+	writeTo(ADXL345_THRESH_FF, _b);  
+}
+
+// Gets the THRESH_FF register.
+int ADXL345::getFreeFallThreshold() {
+	byte _b;
+	readFrom(ADXL345_THRESH_FF, 1, &_b);  
+	return int (_b);
+}
+
+// Sets the TIME_FF register, which holds an unsigned time value representing the minimum
+// time that the RSS value of all axes must be less than THRESH_FF to generate a free-fall 
+// interrupt. The scale factor is 5ms/LSB. A value of 0 may result in undesirable behavior if
+// the free-fall interrupt is enabled. The maximum value is 255.
+void ADXL345::setFreeFallDuration(int freeFallDuration) {
+	freeFallDuration = constrain(freeFallDuration,0,255);  
+	byte _b = byte (freeFallDuration);
+	writeTo(ADXL345_TIME_FF, _b);  
+}
+
+// Gets the TIME_FF register.
+int ADXL345::getFreeFallDuration() {
+	byte _b;
+	readFrom(ADXL345_TIME_FF, 1, &_b);  
+	return int (_b);
+}
+
+bool ADXL345::isActivityXEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 6); 
+}
+bool ADXL345::isActivityYEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 5); 
+}
+bool ADXL345::isActivityZEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 4); 
+}
+bool ADXL345::isInactivityXEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 2); 
+}
+bool ADXL345::isInactivityYEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 1); 
+}
+bool ADXL345::isInactivityZEnabled() {  
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 0); 
+}
+
+void ADXL345::setActivityX(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 6, state); 
+}
+void ADXL345::setActivityY(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 5, state); 
+}
+void ADXL345::setActivityZ(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 4, state); 
+}
+void ADXL345::setInactivityX(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 2, state); 
+}
+void ADXL345::setInactivityY(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 1, state); 
+}
+void ADXL345::setInactivityZ(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 0, state); 
+}
+
+bool ADXL345::isActivityAc() { 
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 7); 
+}
+bool ADXL345::isInactivityAc(){ 
+	return getRegisterBit(ADXL345_ACT_INACT_CTL, 3); 
+}
+
+void ADXL345::setActivityAc(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 7, state); 
+}
+void ADXL345::setInactivityAc(bool state) {  
+	setRegisterBit(ADXL345_ACT_INACT_CTL, 3, state); 
+}
+
+bool ADXL345::getSuppressBit(){ 
+	return getRegisterBit(ADXL345_TAP_AXES, 3); 
+}
+void ADXL345::setSuppressBit(bool state) {  
+	setRegisterBit(ADXL345_TAP_AXES, 3, state); 
+}
+
+bool ADXL345::isTapDetectionOnX(){ 
+	return getRegisterBit(ADXL345_TAP_AXES, 2); 
+}
+void ADXL345::setTapDetectionOnX(bool state) {  
+	setRegisterBit(ADXL345_TAP_AXES, 2, state); 
+}
+bool ADXL345::isTapDetectionOnY(){ 
+	return getRegisterBit(ADXL345_TAP_AXES, 1); 
+}
+void ADXL345::setTapDetectionOnY(bool state) {  
+	setRegisterBit(ADXL345_TAP_AXES, 1, state); 
+}
+bool ADXL345::isTapDetectionOnZ(){ 
+	return getRegisterBit(ADXL345_TAP_AXES, 0); 
+}
+void ADXL345::setTapDetectionOnZ(bool state) {  
+	setRegisterBit(ADXL345_TAP_AXES, 0, state); 
+}
+
+bool ADXL345::isActivitySourceOnX(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 6); 
+}
+bool ADXL345::isActivitySourceOnY(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 5); 
+}
+bool ADXL345::isActivitySourceOnZ(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 4); 
+}
+
+bool ADXL345::isTapSourceOnX(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 2); 
+}
+bool ADXL345::isTapSourceOnY(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 1); 
+}
+bool ADXL345::isTapSourceOnZ(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 0); 
+}
+
+bool ADXL345::isAsleep(){ 
+	return getRegisterBit(ADXL345_ACT_TAP_STATUS, 3); 
+}
+
+bool ADXL345::isLowPower(){ 
+	return getRegisterBit(ADXL345_BW_RATE, 4); 
+}
+void ADXL345::setLowPower(bool state) {  
+	setRegisterBit(ADXL345_BW_RATE, 4, state); 
+}
+
+double ADXL345::getRate(){
+	byte _b;
+	readFrom(ADXL345_BW_RATE, 1, &_b);
+	_b &= B00001111;
+	return (pow(2,((int) _b)-6)) * 6.25;
+}
+
+void ADXL345::setRate(double rate){
+	byte _b,_s;
+	int v = (int) (rate / 6.25);
+	int r = 0;
+	while (v >>= 1)
+	{
+		r++;
+	}
+	if (r <= 9) { 
+		readFrom(ADXL345_BW_RATE, 1, &_b);
+		_s = (byte) (r + 6) | (_b & B11110000);
+		writeTo(ADXL345_BW_RATE, _s);
+	}
+}
+
+void ADXL345::set_bw(byte bw_code){
+	if((bw_code < ADXL345_BW_3) || (bw_code > ADXL345_BW_1600)){
+		status = false;
+		error_code = ADXL345_BAD_ARG;
+	}
+	else{
+		writeTo(ADXL345_BW_RATE, bw_code);
+	}
+}
+
+byte ADXL345::get_bw_code(){
+	byte bw_code;
+	readFrom(ADXL345_BW_RATE, 1, &bw_code);
+	return bw_code;
+}
+
+
+
+
+
+//Used to check if action was triggered in interrupts
+//Example triggered(interrupts, ADXL345_SINGLE_TAP);
+bool ADXL345::triggered(byte interrupts, int mask){
+	return ((interrupts >> mask) & 1);
+}
+
+
+/*
+ ADXL345_DATA_READY
+ ADXL345_SINGLE_TAP
+ ADXL345_DOUBLE_TAP
+ ADXL345_ACTIVITY
+ ADXL345_INACTIVITY
+ ADXL345_FREE_FALL
+ ADXL345_WATERMARK
+ ADXL345_OVERRUNY
+ */
+
+
+
+
+
+byte ADXL345::getInterruptSource() {
+	byte _b;
+	readFrom(ADXL345_INT_SOURCE, 1, &_b);
+	return _b;
+}
+
+bool ADXL345::getInterruptSource(byte interruptBit) {
+	return getRegisterBit(ADXL345_INT_SOURCE,interruptBit);
+}
+
+bool ADXL345::getInterruptMapping(byte interruptBit) {
+	return getRegisterBit(ADXL345_INT_MAP,interruptBit);
+}
+
+// Set the mapping of an interrupt to pin1 or pin2
+// eg: setInterruptMapping(ADXL345_INT_DOUBLE_TAP_BIT,ADXL345_INT2_PIN);
+void ADXL345::setInterruptMapping(byte interruptBit, bool interruptPin) {
+	setRegisterBit(ADXL345_INT_MAP, interruptBit, interruptPin);
+}
+
+bool ADXL345::isInterruptEnabled(byte interruptBit) {
+	return getRegisterBit(ADXL345_INT_ENABLE,interruptBit);
+}
+
+void ADXL345::setInterrupt(byte interruptBit, bool state) {
+	setRegisterBit(ADXL345_INT_ENABLE, interruptBit, state);
+}
+
+void ADXL345::setRegisterBit(byte regAdress, int bitPos, bool state) {
+	byte _b;
+	readFrom(regAdress, 1, &_b);
+	if (state) {
+		_b |= (1 << bitPos);  // forces nth bit of _b to be 1.  all other bits left alone.
+	} 
+	else {
+		_b &= ~(1 << bitPos); // forces nth bit of _b to be 0.  all other bits left alone.
+	}
+	writeTo(regAdress, _b);  
+}
+
+bool ADXL345::getRegisterBit(byte regAdress, int bitPos) {
+	byte _b;
+	readFrom(regAdress, 1, &_b);
+	return ((_b >> bitPos) & 1);
+}
+
+// print all register value to the serial ouptut, which requires it to be setup
+// this can be used to manually to check the current configuration of the device
+void ADXL345::printAllRegister() {
+	byte _b;
+	Serial.print("0x00: ");
+	readFrom(0x00, 1, &_b);
+	print_byte(_b);
+	Serial.println("");
+	int i;
+	for (i=29;i<=57;i++){
+		Serial.print("0x");
+		Serial.print(i, HEX);
+		Serial.print(": ");
+		readFrom(i, 1, &_b);
+		print_byte(_b);
+		Serial.println("");    
+	}
+}
+
+void print_byte(byte val){
+	int i;
+	Serial.print("B");
+	for(i=7; i>=0; i--){
+		Serial.print(val >> i & 1, BIN);
+	}
+}

+ 221 - 0
DigitalAccelerometer_ADXL345/ADXL345.h

@@ -0,0 +1,221 @@
+/*****************************************************************************/
+//	Function:    Header file for class ADXL345
+//  Hardware:    3-Axis Digital Accelerometer(¡À16g)
+//	Arduino IDE: Arduino-1.0
+//	Author:	 Frankie.Chu		
+//	Date: 	 Jan 11,2013
+//	Version: v1.0
+//	by www.seeedstudio.com
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License, or (at your option) any later version.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+/*******************************************************************************/
+#include "Arduino.h"
+
+#ifndef ADXL345_h
+#define ADXL345_h
+
+/* ------- Register names ------- */
+#define ADXL345_DEVID 0x00
+#define ADXL345_RESERVED1 0x01
+#define ADXL345_THRESH_TAP 0x1d
+#define ADXL345_OFSX 0x1e
+#define ADXL345_OFSY 0x1f
+#define ADXL345_OFSZ 0x20
+#define ADXL345_DUR 0x21
+#define ADXL345_LATENT 0x22
+#define ADXL345_WINDOW 0x23
+#define ADXL345_THRESH_ACT 0x24
+#define ADXL345_THRESH_INACT 0x25
+#define ADXL345_TIME_INACT 0x26
+#define ADXL345_ACT_INACT_CTL 0x27
+#define ADXL345_THRESH_FF 0x28
+#define ADXL345_TIME_FF 0x29
+#define ADXL345_TAP_AXES 0x2a
+#define ADXL345_ACT_TAP_STATUS 0x2b
+#define ADXL345_BW_RATE 0x2c
+#define ADXL345_POWER_CTL 0x2d
+#define ADXL345_INT_ENABLE 0x2e
+#define ADXL345_INT_MAP 0x2f
+#define ADXL345_INT_SOURCE 0x30
+#define ADXL345_DATA_FORMAT 0x31
+#define ADXL345_DATAX0 0x32
+#define ADXL345_DATAX1 0x33
+#define ADXL345_DATAY0 0x34
+#define ADXL345_DATAY1 0x35
+#define ADXL345_DATAZ0 0x36
+#define ADXL345_DATAZ1 0x37
+#define ADXL345_FIFO_CTL 0x38
+#define ADXL345_FIFO_STATUS 0x39
+
+#define ADXL345_BW_1600 0xF // 1111
+#define ADXL345_BW_800  0xE // 1110
+#define ADXL345_BW_400  0xD // 1101  
+#define ADXL345_BW_200  0xC // 1100
+#define ADXL345_BW_100  0xB // 1011  
+#define ADXL345_BW_50   0xA // 1010 
+#define ADXL345_BW_25   0x9 // 1001 
+#define ADXL345_BW_12   0x8 // 1000 
+#define ADXL345_BW_6    0x7 // 0111
+#define ADXL345_BW_3    0x6 // 0110
+
+
+/* 
+ Interrupt PINs
+ INT1: 0
+ INT2: 1
+ */
+#define ADXL345_INT1_PIN 0x00
+#define ADXL345_INT2_PIN 0x01
+
+/*Interrupt bit position*/
+#define ADXL345_INT_DATA_READY_BIT 0x07
+#define ADXL345_INT_SINGLE_TAP_BIT 0x06
+#define ADXL345_INT_DOUBLE_TAP_BIT 0x05
+#define ADXL345_INT_ACTIVITY_BIT   0x04
+#define ADXL345_INT_INACTIVITY_BIT 0x03
+#define ADXL345_INT_FREE_FALL_BIT  0x02
+#define ADXL345_INT_WATERMARK_BIT  0x01
+#define ADXL345_INT_OVERRUNY_BIT   0x00
+
+#define ADXL345_DATA_READY 0x07
+#define ADXL345_SINGLE_TAP 0x06
+#define ADXL345_DOUBLE_TAP 0x05
+#define ADXL345_ACTIVITY   0x04
+#define ADXL345_INACTIVITY 0x03
+#define ADXL345_FREE_FALL  0x02
+#define ADXL345_WATERMARK  0x01
+#define ADXL345_OVERRUNY   0x00
+
+#define ADXL345_OK    1 // no error
+#define ADXL345_ERROR 0 // indicates error is predent
+
+#define ADXL345_NO_ERROR   0 // initial state
+#define ADXL345_READ_ERROR 1 // problem reading accel
+#define ADXL345_BAD_ARG    2 // bad method argument
+
+class ADXL345
+{
+public:
+	bool status;           // set when error occurs 
+	// see error code for details
+	byte error_code;       // Initial state
+	double gains[3];        // counts to Gs
+	
+	ADXL345();
+	void powerOn();
+	void readAccel(int* xyx);
+	void readXYZ(int* x, int* y, int* z);
+	void getAcceleration(double *xyz);
+	
+	void setTapThreshold(int tapThreshold);
+	int getTapThreshold();
+	void setAxisGains(double *_gains);
+	void getAxisGains(double *_gains);
+	void setAxisOffset(int x, int y, int z);
+	void getAxisOffset(int* x, int* y, int*z);
+	void setTapDuration(int tapDuration);
+	int getTapDuration();
+	void setDoubleTapLatency(int doubleTapLatency);
+	int getDoubleTapLatency();
+	void setDoubleTapWindow(int doubleTapWindow);
+	int getDoubleTapWindow();
+	void setActivityThreshold(int activityThreshold);
+	int getActivityThreshold();
+	void setInactivityThreshold(int inactivityThreshold);
+	int getInactivityThreshold();
+	void setTimeInactivity(int timeInactivity);
+	int getTimeInactivity();
+	void setFreeFallThreshold(int freeFallthreshold);
+	int getFreeFallThreshold();
+	void setFreeFallDuration(int freeFallDuration);
+	int getFreeFallDuration();
+	
+	bool isActivityXEnabled();
+	bool isActivityYEnabled();
+	bool isActivityZEnabled();
+	bool isInactivityXEnabled();
+	bool isInactivityYEnabled();
+	bool isInactivityZEnabled();
+	bool isActivityAc();
+	bool isInactivityAc();
+	void setActivityAc(bool state);
+	void setInactivityAc(bool state);
+	
+	bool getSuppressBit();
+	void setSuppressBit(bool state);
+	bool isTapDetectionOnX();
+	void setTapDetectionOnX(bool state);
+	bool isTapDetectionOnY();
+	void setTapDetectionOnY(bool state);
+	bool isTapDetectionOnZ();
+	void setTapDetectionOnZ(bool state);
+	
+	void setActivityX(bool state);
+	void setActivityY(bool state);
+	void setActivityZ(bool state);
+	void setInactivityX(bool state);
+	void setInactivityY(bool state);
+	void setInactivityZ(bool state);
+	
+	bool isActivitySourceOnX();
+	bool isActivitySourceOnY();
+	bool isActivitySourceOnZ();
+	bool isTapSourceOnX();
+	bool isTapSourceOnY();
+	bool isTapSourceOnZ();
+	bool isAsleep();
+	
+	bool isLowPower();
+	void setLowPower(bool state);
+	double getRate();
+	void setRate(double rate);
+	void set_bw(byte bw_code);
+	byte get_bw_code();  
+	
+	
+	bool triggered(byte interrupts, int mask);
+	
+	
+	byte getInterruptSource();
+	bool getInterruptSource(byte interruptBit);
+	bool getInterruptMapping(byte interruptBit);
+	void setInterruptMapping(byte interruptBit, bool interruptPin);
+	bool isInterruptEnabled(byte interruptBit);
+	void setInterrupt(byte interruptBit, bool state);
+	
+	void getRangeSetting(byte* rangeSetting);
+	void setRangeSetting(int val);
+	bool getSelfTestBit();
+	void setSelfTestBit(bool selfTestBit);
+	bool getSpiBit();
+	void setSpiBit(bool spiBit);
+	bool getInterruptLevelBit();
+	void setInterruptLevelBit(bool interruptLevelBit);
+	bool getFullResBit();
+	void setFullResBit(bool fullResBit);
+	bool getJustifyBit();
+	void setJustifyBit(bool justifyBit);
+	void printAllRegister();
+	
+private:
+	void writeTo(byte address, byte val);
+	void readFrom(byte address, int num, byte buff[]);
+	void setRegisterBit(byte regAdress, int bitPos, bool state);
+	bool getRegisterBit(byte regAdress, int bitPos);  
+	byte _buff[6] ;    //6 bytes buffer for saving data read from the device
+};
+void print_byte(byte val);
+#endif

+ 339 - 0
DigitalAccelerometer_ADXL345/License.txt

@@ -0,0 +1,339 @@
+GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.

+ 114 - 0
DigitalAccelerometer_ADXL345/examples/ADXL345_demo_code/ADXL345_demo_code.ino

@@ -0,0 +1,114 @@
+/*****************************************************************************/
+//	Function:    Get the accelemeter of X/Y/Z axis and print out on the 
+//					serial monitor.
+//  Hardware:    3-Axis Digital Accelerometer(��16g)
+//	Arduino IDE: Arduino-1.0
+//	Author:	 Frankie.Chu		
+//	Date: 	 Jan 11,2013
+//	Version: v1.0
+//	by www.seeedstudio.com
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License, or (at your option) any later version.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+/*******************************************************************************/
+
+#include <Wire.h>
+#include <ADXL345.h>
+
+
+ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
+
+void setup(){
+  Serial.begin(9600);
+  adxl.powerOn();
+
+  //set activity/ inactivity thresholds (0-255)
+  adxl.setActivityThreshold(75); //62.5mg per increment
+  adxl.setInactivityThreshold(75); //62.5mg per increment
+  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
+ 
+  //look of activity movement on this axes - 1 == on; 0 == off 
+  adxl.setActivityX(1);
+  adxl.setActivityY(1);
+  adxl.setActivityZ(1);
+ 
+  //look of inactivity movement on this axes - 1 == on; 0 == off
+  adxl.setInactivityX(1);
+  adxl.setInactivityY(1);
+  adxl.setInactivityZ(1);
+ 
+  //look of tap movement on this axes - 1 == on; 0 == off
+  adxl.setTapDetectionOnX(0);
+  adxl.setTapDetectionOnY(0);
+  adxl.setTapDetectionOnZ(1);
+ 
+  //set values for what is a tap, and what is a double tap (0-255)
+  adxl.setTapThreshold(50); //62.5mg per increment
+  adxl.setTapDuration(15); //625us per increment
+  adxl.setDoubleTapLatency(80); //1.25ms per increment
+  adxl.setDoubleTapWindow(200); //1.25ms per increment
+ 
+  //set values for what is considered freefall (0-255)
+  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
+  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
+ 
+  //setting all interrupts to take place on int pin 1
+  //I had issues with int pin 2, was unable to reset it
+  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
+  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
+  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
+  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
+  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
+ 
+  //register interrupt actions - 1 == on; 0 == off  
+  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
+  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
+  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);
+  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);
+  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
+}
+
+void loop(){
+  
+	//Boring accelerometer stuff   
+	int x,y,z;  
+	adxl.readXYZ(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z
+	// Output x,y,z values 
+	Serial.print("values of X , Y , Z: ");
+	Serial.print(x);
+	Serial.print(" , ");
+	Serial.print(y);
+	Serial.print(" , ");
+	Serial.println(z);
+	
+	double xyz[3];
+	double ax,ay,az;
+	adxl.getAcceleration(xyz);
+	ax = xyz[0];
+	ay = xyz[1];
+	az = xyz[2];
+	Serial.print("X=");
+	Serial.print(ax);
+    Serial.println(" g");
+	Serial.print("Y=");
+	Serial.print(ay);
+    Serial.println(" g");
+	Serial.print("Z=");
+	Serial.println(az);
+    Serial.println(" g");
+	Serial.println("**********************");
+	delay(500);
+ 
+}