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:
- 11:65ae1cf6f7d9
- Parent:
- 10:7bdbc8eb0d69
- Child:
- 12:509ed716bd58
--- a/main.cpp Sat Jan 10 15:41:56 2015 +0000 +++ b/main.cpp Sat Jan 10 18:54:57 2015 +0000 @@ -1,10 +1,10 @@ #include "mbed.h" //Accelerometer -#define ADXL345_ADDRESS (0xA6 >> 1) +#define ADXL345_ADDRESS (0xA6 >> 1) //I2C uses 7 bits, must shift it by 1 to use #define ADXL345_REGISTER_XLSB (0x32) #define ADXL_REGISTER_PWRCTL (0x2D) -#define ADXL_PWRCTL_MEASURE (1 << 3) +#define ADXL_PWRCTL_MEASURE (0x01 << 3) //Gyroscope #define ITG3200_ADDRESS (0xD0 >> 1) @@ -19,13 +19,12 @@ #define HMC5843_REGISTER_MEASMODE (0x02) #define HMC5843_MEASMODE_CONT (0x00) -//I2C i2c( p9, p10 ); // sda, scl +I2C i2c( p9, p10 ); // sda, scl -//void init_adxl345(); +void init_adxl345(); //void init_itg3200(); //void init_hmc5843(); -const int addr = 0x90; Serial pc(USBTX, USBRX); //tx, rx //int adxl345_Data[3]; @@ -39,7 +38,7 @@ int main() { //char cmd[2]; - //init_adxl345(); + init_adxl345(); //init_hmc5843(); //init_itg3200(); @@ -50,6 +49,8 @@ //cmd[1] = 0x00; //i2c.write(addr, cmd, 2); // i2c.write(address, command, bytes); + pc.printf("ADXL345_Address %d", ADXL345_ADDRESS); + char c = pc.getc(); if((c == 'u') && (brightness < 0.5)) { brightness += 0.01; @@ -64,16 +65,22 @@ } -/* + void init_adxl345() { - char data = 0; + char data[2]; + data[0] = ADXL_REGISTER_PWRCTL; + data[1] = ADXL_PWRCTL_MEASURE; - i2c_write(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, ADXL_PWRCTL_MEASURE); + i2c.write(ADXL345_ADDRESS, data, 2); // first part of data is the register + + wait(0.5); - i2c_read(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, 1, &data); - Serial.println((unsigned int)data); + i2c.write(ADXL345_ADDRESS, data, 1); + i2c.read(ADXL345_ADDRESS, data, 2); + pc.printf("%c",(char)data); } +/* void read_adxl345() { bytes bytes[6]; memset(bytes,0,6);