Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 14:762baad15486
- Parent:
- 13:83bea035c658
- Child:
- 16:1121b66ef27b
diff -r 83bea035c658 -r 762baad15486 main.cpp
--- a/main.cpp Sat Jan 10 19:37:34 2015 +0000
+++ b/main.cpp Sun Jan 11 04:34:14 2015 +0000
@@ -1,7 +1,8 @@
#include "mbed.h"
//Accelerometer
-#define ADXL345_ADDRESS (0xA6 >> 1) //I2C uses 7 bits, must shift it by 1 to use
+#define ADXL345_ADDRESS_W (0xA6)
+#define ADXL345_ADDRESS_R (0xA7)
#define ADXL345_REGISTER_XLSB (0x32)
#define ADXL_REGISTER_PWRCTL (0x2D)
#define ADXL_PWRCTL_MEASURE (0x01 << 3)
@@ -66,12 +67,12 @@
data[0] = ADXL_REGISTER_PWRCTL;
data[1] = ADXL_PWRCTL_MEASURE;
- i2c.write(ADXL345_ADDRESS, data, 2); // first part of data is the register
+ i2c.write(ADXL345_ADDRESS_W, data, 2); // first part of data is the register
wait(0.5);
- i2c.write(ADXL345_ADDRESS, data, 1);
- i2c.read(ADXL345_ADDRESS, data, 2);
+ i2c.write(ADXL345_ADDRESS_W, data, 1);
+ i2c.read(ADXL345_ADDRESS_R, data, 2);
pc.printf("%i\n",(unsigned int)data);
}
@@ -80,8 +81,8 @@
memset(bytes,0,6);
bytes[0] = ADXL345_REGISTER_XLSB;
- i2c.write(ADXL345_ADDRESS, bytes, 1);
- i2c.read(ADXL345_ADDRESS, bytes, 6);
+ i2c.write(ADXL345_ADDRESS_W, bytes, 1);
+ i2c.read(ADXL345_ADDRESS_R, bytes, 6);
for (int i=0;i<3;++i) {
accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);