Alexandre Lemay
/
APP1_s5_A17
PARTYYYY
Accelerometre.cpp@5:70db90b673b9, 2017-09-05 (annotated)
- Committer:
- evrast
- Date:
- Tue Sep 05 00:05:38 2017 +0000
- Revision:
- 5:70db90b673b9
- Parent:
- 2:3576839565ae
- Parent:
- 4:ab14f0e33f2b
- Child:
- 6:909e7877d915
Merged;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evrast | 0:c2282db9d19e | 1 | #include "Accelerometre.h" |
evrast | 0:c2282db9d19e | 2 | |
evrast | 0:c2282db9d19e | 3 | |
evrast | 3:56cd9dff3b5f | 4 | Accelerometre::Accelerometre():i2c(p9,p10),pc(USBTX, USBRX),acc(p9, p10, 40000){ |
evrast | 4:ab14f0e33f2b | 5 | |
evrast | 4:ab14f0e33f2b | 6 | acc.setBitDepth(MMA8452::BIT_DEPTH_12); |
evrast | 4:ab14f0e33f2b | 7 | acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); |
evrast | 4:ab14f0e33f2b | 8 | acc.setDataRate(MMA8452::RATE_100); |
evrast | 4:ab14f0e33f2b | 9 | |
evrast | 3:56cd9dff3b5f | 10 | } |
evrast | 3:56cd9dff3b5f | 11 | |
evrast | 4:ab14f0e33f2b | 12 | void Accelerometre::readxyzAngle(double *Angle){ |
evrast | 4:ab14f0e33f2b | 13 | double x=0, y=0, z=0; |
evrast | 4:ab14f0e33f2b | 14 | acc.readXYZGravity(&x,&y,&z); |
evrast | 4:ab14f0e33f2b | 15 | *Angle = AngleCalculation(z); |
evrast | 3:56cd9dff3b5f | 16 | |
evrast | 3:56cd9dff3b5f | 17 | } |
evrast | 3:56cd9dff3b5f | 18 | |
evrast | 4:ab14f0e33f2b | 19 | double Accelerometre::AngleCalculation(double ZValue){ |
evrast | 4:ab14f0e33f2b | 20 | if(ZValue>1){ |
evrast | 4:ab14f0e33f2b | 21 | ZValue = 1; |
evrast | 4:ab14f0e33f2b | 22 | } |
evrast | 5:70db90b673b9 | 23 | double angle =std::acos(ZValue); |
evrast | 5:70db90b673b9 | 24 | return (angle*180* PI); |
evrast | 3:56cd9dff3b5f | 25 | |
evrast | 3:56cd9dff3b5f | 26 | |
evrast | 4:ab14f0e33f2b | 27 | } |
evrast | 4:ab14f0e33f2b | 28 | |
evrast | 3:56cd9dff3b5f | 29 | |
evrast | 3:56cd9dff3b5f | 30 | //int Accelerometre::readSingleByte(int regis){ |
evrast | 3:56cd9dff3b5f | 31 | // int c; |
evrast | 3:56cd9dff3b5f | 32 | // pc.printf("Reading single byte\n"); |
evrast | 3:56cd9dff3b5f | 33 | // i2c.start(); |
evrast | 3:56cd9dff3b5f | 34 | // int a=i2c.write(WRITE_DATA); // A write to device |
evrast | 3:56cd9dff3b5f | 35 | // i2c.write(regis); // Register to read from (acceleration in X) |
evrast | 3:56cd9dff3b5f | 36 | // i2c.start(); // Need to send start condition here |
evrast | 3:56cd9dff3b5f | 37 | // i2c.write(READ_DATA); // tell devide you want to read |
evrast | 3:56cd9dff3b5f | 38 | // c=i2c.read(0); |
evrast | 3:56cd9dff3b5f | 39 | // i2c.stop(); |
evrast | 3:56cd9dff3b5f | 40 | // pc.printf("value is %d\n", c); |
evrast | 3:56cd9dff3b5f | 41 | // pc.printf("end\n"); |
evrast | 3:56cd9dff3b5f | 42 | // return c; |
evrast | 3:56cd9dff3b5f | 43 | // } |
evrast | 3:56cd9dff3b5f | 44 | |
evrast | 0:c2282db9d19e | 45 | |
evrast | 3:56cd9dff3b5f | 46 | void Accelerometre::writeByte(int regis,int data){ |
evrast | 0:c2282db9d19e | 47 | pc.printf("Reading single byte\n"); |
evrast | 0:c2282db9d19e | 48 | i2c.start(); |
evrast | 3:56cd9dff3b5f | 49 | i2c.write(WRITE_DATA); // A write to device |
evrast | 0:c2282db9d19e | 50 | i2c.write(regis); // Register to read from (acceleration in X) |
evrast | 3:56cd9dff3b5f | 51 | i2c.write(data); |
evrast | 0:c2282db9d19e | 52 | i2c.stop(); |
evrast | 0:c2282db9d19e | 53 | pc.printf("end\n"); |
evrast | 5:70db90b673b9 | 54 | } |
evrast | 5:70db90b673b9 | 55 |