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.
main.cpp@0:43edf2e11fc0, 2019-07-26 (annotated)
- Committer:
- jorgmassih
- Date:
- Fri Jul 26 00:06:28 2019 +0000
- Revision:
- 0:43edf2e11fc0
- Child:
- 1:741df8410d1f
- Child:
- 2:4fa4c952883a
First commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jorgmassih | 0:43edf2e11fc0 | 1 | #include "mbed.h" |
| jorgmassih | 0:43edf2e11fc0 | 2 | #include "MPU6050.h" |
| jorgmassih | 0:43edf2e11fc0 | 3 | #include "REFVALUES.h" |
| jorgmassih | 0:43edf2e11fc0 | 4 | |
| jorgmassih | 0:43edf2e11fc0 | 5 | // Debbuging led |
| jorgmassih | 0:43edf2e11fc0 | 6 | DigitalOut myled(LED1); |
| jorgmassih | 0:43edf2e11fc0 | 7 | |
| jorgmassih | 0:43edf2e11fc0 | 8 | // Puerto serial |
| jorgmassih | 0:43edf2e11fc0 | 9 | Serial pc(USBTX, USBRX); |
| jorgmassih | 0:43edf2e11fc0 | 10 | |
| jorgmassih | 0:43edf2e11fc0 | 11 | // Objeto MPU6050 |
| jorgmassih | 0:43edf2e11fc0 | 12 | MPU6050 mpu(PF_15, PF_14); |
| jorgmassih | 0:43edf2e11fc0 | 13 | |
| jorgmassih | 0:43edf2e11fc0 | 14 | // Threads |
| jorgmassih | 0:43edf2e11fc0 | 15 | Thread sampleAccelero(); |
| jorgmassih | 0:43edf2e11fc0 | 16 | Thread printDebug(); |
| jorgmassih | 0:43edf2e11fc0 | 17 | |
| jorgmassih | 0:43edf2e11fc0 | 18 | |
| jorgmassih | 0:43edf2e11fc0 | 19 | |
| jorgmassih | 0:43edf2e11fc0 | 20 | |
| jorgmassih | 0:43edf2e11fc0 | 21 | |
| jorgmassih | 0:43edf2e11fc0 | 22 | int main() { |
| jorgmassih | 0:43edf2e11fc0 | 23 | |
| jorgmassih | 0:43edf2e11fc0 | 24 | pc.baud(9600); |
| jorgmassih | 0:43edf2e11fc0 | 25 | |
| jorgmassih | 0:43edf2e11fc0 | 26 | |
| jorgmassih | 0:43edf2e11fc0 | 27 | |
| jorgmassih | 0:43edf2e11fc0 | 28 | float acce[3]; |
| jorgmassih | 0:43edf2e11fc0 | 29 | |
| jorgmassih | 0:43edf2e11fc0 | 30 | mpu.setAcceleroRange(2); |
| jorgmassih | 0:43edf2e11fc0 | 31 | mpu.setBW(6); |
| jorgmassih | 0:43edf2e11fc0 | 32 | |
| jorgmassih | 0:43edf2e11fc0 | 33 | // Test the connection |
| jorgmassih | 0:43edf2e11fc0 | 34 | if (mpu.testConnection()) |
| jorgmassih | 0:43edf2e11fc0 | 35 | pc.printf("MPU6050 test passed \r\n"); |
| jorgmassih | 0:43edf2e11fc0 | 36 | else |
| jorgmassih | 0:43edf2e11fc0 | 37 | pc.printf("MPU6050 test failed \r\n"); |
| jorgmassih | 0:43edf2e11fc0 | 38 | |
| jorgmassih | 0:43edf2e11fc0 | 39 | |
| jorgmassih | 0:43edf2e11fc0 | 40 | float x; |
| jorgmassih | 0:43edf2e11fc0 | 41 | float y; |
| jorgmassih | 0:43edf2e11fc0 | 42 | |
| jorgmassih | 0:43edf2e11fc0 | 43 | while(1) { |
| jorgmassih | 0:43edf2e11fc0 | 44 | |
| jorgmassih | 0:43edf2e11fc0 | 45 | wait(0.016); |
| jorgmassih | 0:43edf2e11fc0 | 46 | mpu.getAccelero(acce); |
| jorgmassih | 0:43edf2e11fc0 | 47 | |
| jorgmassih | 0:43edf2e11fc0 | 48 | |
| jorgmassih | 0:43edf2e11fc0 | 49 | x = (float)acce[0] / (9.81); |
| jorgmassih | 0:43edf2e11fc0 | 50 | y = (float)acce[1] / (9.81); |
| jorgmassih | 0:43edf2e11fc0 | 51 | |
| jorgmassih | 0:43edf2e11fc0 | 52 | |
| jorgmassih | 0:43edf2e11fc0 | 53 | //pc.printf("X = %f \t Y = %f \t Z = %f \r\n", x , y, z); |
| jorgmassih | 0:43edf2e11fc0 | 54 | pc.printf("X = %f \t Y = %f \r\n", x , y); |
| jorgmassih | 0:43edf2e11fc0 | 55 | //pc.printf("%f\r\n", x); |
| jorgmassih | 0:43edf2e11fc0 | 56 | |
| jorgmassih | 0:43edf2e11fc0 | 57 | } |
| jorgmassih | 0:43edf2e11fc0 | 58 | } |
