for textbook v4.4

Dependencies:   mbed HEPTA_EPS

Committer:
HeptaSatTraining2019
Date:
Tue Aug 27 04:12:49 2019 +0000
Revision:
26:993102540f3d
Parent:
25:efb6bdda7c02

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
HeptaSatTraining2019 26:993102540f3d 2 #include "HEPTA_EPS.h"
umeume 2:1c5cdb2c3e0f 3
umeume 2:1c5cdb2c3e0f 4 Serial pc(USBTX,USBRX);
HeptaSatTraining2019 21:92c25e853b87 5 HEPTA_EPS eps(p16,p26);
HeptaSatTraining2019 25:efb6bdda7c02 6 I2C i2c(p28, p27);
umeume 2:1c5cdb2c3e0f 7
HeptaSatTraining2019 25:efb6bdda7c02 8 const int addr_accel_gyro = 0xD0;
HeptaSatTraining2019 25:efb6bdda7c02 9 char cmd[2];
HeptaSatTraining2019 25:efb6bdda7c02 10 const int addr_compus = 0x18;
HeptaSatTraining2019 25:efb6bdda7c02 11 short int mxl,mxh,myl,myh,mzl,mzh,st2;
umeume 2:1c5cdb2c3e0f 12 int main()
umeume 2:1c5cdb2c3e0f 13 {
HeptaSatTraining2019 25:efb6bdda7c02 14 i2c.frequency(100000);
HeptaSatTraining2019 25:efb6bdda7c02 15 cmd[0]=0x6B;
HeptaSatTraining2019 25:efb6bdda7c02 16 cmd[1]=0x00;
HeptaSatTraining2019 25:efb6bdda7c02 17 i2c.write(addr_accel_gyro,cmd,2);
HeptaSatTraining2019 25:efb6bdda7c02 18 cmd[0] = 0x37;
HeptaSatTraining2019 25:efb6bdda7c02 19 cmd[1] = 0x02;
HeptaSatTraining2019 25:efb6bdda7c02 20 i2c.write(addr_accel_gyro,cmd,2);
HeptaSatTraining2019 25:efb6bdda7c02 21 i2c.stop();
HeptaSatTraining2019 25:efb6bdda7c02 22 while(1) {
HeptaSatTraining2019 25:efb6bdda7c02 23 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 24 i2c.write(addr_compus);
HeptaSatTraining2019 25:efb6bdda7c02 25 i2c.write(0x0A);
HeptaSatTraining2019 25:efb6bdda7c02 26 i2c.write(0x12);
HeptaSatTraining2019 25:efb6bdda7c02 27 i2c.stop();
HeptaSatTraining2019 25:efb6bdda7c02 28 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 29 i2c.write(addr_compus);
HeptaSatTraining2019 25:efb6bdda7c02 30 i2c.write(0x03);
HeptaSatTraining2019 25:efb6bdda7c02 31 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 32 i2c.write(addr_compus|0x01);
HeptaSatTraining2019 25:efb6bdda7c02 33 mxl = i2c.read(0);
HeptaSatTraining2019 25:efb6bdda7c02 34 i2c.stop();
HeptaSatTraining2019 25:efb6bdda7c02 35 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 36 i2c.write(addr_compus);
HeptaSatTraining2019 25:efb6bdda7c02 37 i2c.write(0x04);
HeptaSatTraining2019 25:efb6bdda7c02 38 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 39 i2c.write(addr_compus|0x01);
HeptaSatTraining2019 25:efb6bdda7c02 40 mxh = i2c.read(0);
HeptaSatTraining2019 25:efb6bdda7c02 41 i2c.stop();
HeptaSatTraining2019 25:efb6bdda7c02 42 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 43 i2c.write(addr_compus);
HeptaSatTraining2019 25:efb6bdda7c02 44 i2c.write(0x09);
HeptaSatTraining2019 25:efb6bdda7c02 45 i2c.start();
HeptaSatTraining2019 25:efb6bdda7c02 46 i2c.write(addr_compus|0x01);
HeptaSatTraining2019 25:efb6bdda7c02 47 st2 = i2c.read(0);
HeptaSatTraining2019 25:efb6bdda7c02 48 i2c.stop();
HeptaSatTraining2019 25:efb6bdda7c02 49 double mg_x = short((mxh<<8) | (mxl));
HeptaSatTraining2019 25:efb6bdda7c02 50 double MX = ( mg_x)*0.15;
HeptaSatTraining2019 25:efb6bdda7c02 51 pc.printf("MX = %f\r\n",MX);
HeptaSatTraining2019 25:efb6bdda7c02 52 wait(0.5);
HeptaSatTraining2019 25:efb6bdda7c02 53 }
umeume 2:1c5cdb2c3e0f 54 }