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.
Dependencies: mbed HeptaBattery
Fork of Lab7-01_template by
main.cpp@14:1becf2edba9c, 2017-09-07 (annotated)
- Committer:
- HEPTA
- Date:
- Thu Sep 07 13:31:00 2017 +0000
- Revision:
- 14:1becf2edba9c
- Parent:
- 13:a1fa75a002f6
- Child:
- 15:c9e7bc2c90b9
Hepta Lab4
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" | 
| HEPTA | 14:1becf2edba9c | 2 | I2C i2c(p28, p27); | 
| HEPTA | 14:1becf2edba9c | 3 | Serial pc(USBTX, USBRX); | 
| HEPTA | 14:1becf2edba9c | 4 | const int addr_accel_gyro = 0xD0; | 
| HEPTA | 14:1becf2edba9c | 5 | char cmd[2]; | 
| HEPTA | 14:1becf2edba9c | 6 | short int xl,xh,yl,yh,zl,zh; | 
| HEPTA | 14:1becf2edba9c | 7 | int main() { | 
| HEPTA | 14:1becf2edba9c | 8 | i2c.frequency(100000); | 
| HEPTA | 14:1becf2edba9c | 9 | cmd[0]=0x6B; | 
| HEPTA | 14:1becf2edba9c | 10 | cmd[1]=0x00; | 
| HEPTA | 14:1becf2edba9c | 11 | i2c.write(addr_accel_gyro,cmd,2); | 
| HEPTA | 14:1becf2edba9c | 12 | cmd[0] = 0x37; | 
| HEPTA | 14:1becf2edba9c | 13 | cmd[1] = 0x02; | 
| HEPTA | 14:1becf2edba9c | 14 | i2c.write(addr_accel_gyro,cmd,2); | 
| HEPTA | 14:1becf2edba9c | 15 | i2c.stop(); | 
| HEPTA | 14:1becf2edba9c | 16 | while(1){ | 
| HEPTA | 14:1becf2edba9c | 17 | i2c.start(); | 
| HEPTA | 14:1becf2edba9c | 18 | i2c.write(addr_accel_gyro); | 
| HEPTA | 14:1becf2edba9c | 19 | i2c.write(0x3b);//read adress | 
| HEPTA | 14:1becf2edba9c | 20 | i2c.start(); | 
| HEPTA | 14:1becf2edba9c | 21 | i2c.write(addr_accel_gyro|0x01); | 
| HEPTA | 14:1becf2edba9c | 22 | xh = i2c.read(0); | 
| HEPTA | 14:1becf2edba9c | 23 | i2c.stop(); | 
| HEPTA | 14:1becf2edba9c | 24 | i2c.start(); | 
| HEPTA | 14:1becf2edba9c | 25 | i2c.write(addr_accel_gyro); | 
| HEPTA | 14:1becf2edba9c | 26 | i2c.write(0x3c); | 
| HEPTA | 14:1becf2edba9c | 27 | i2c.start(); | 
| HEPTA | 14:1becf2edba9c | 28 | i2c.write(addr_accel_gyro|0x01); | 
| HEPTA | 14:1becf2edba9c | 29 | xl = i2c.read(0); | 
| HEPTA | 14:1becf2edba9c | 30 | i2c.stop(); | 
| HEPTA | 14:1becf2edba9c | 31 | double acc_ax = short((xh<<8) | (xl)); | 
| HEPTA | 14:1becf2edba9c | 32 | double AX = (acc_ax)*2/32764*9.81; | 
| HEPTA | 14:1becf2edba9c | 33 | pc.printf("AX = %f\r\n",AX); | 
| HEPTA | 14:1becf2edba9c | 34 | wait(0.5); | 
| HEPTA | 14:1becf2edba9c | 35 | } | 
| umeume | 2:1c5cdb2c3e0f | 36 | } | 
