Jorge Abraham Massih Vargas
/
proyecto_final
Earthquake detector
main.cpp@4:16b60914d174, 2019-07-26 (annotated)
- Committer:
- Alvaro13
- Date:
- Fri Jul 26 00:44:25 2019 +0000
- Revision:
- 4:16b60914d174
- Parent:
- 3:371e35f9769a
el main() anterior ahora es medicion(); se creo un nuevo main() con la inicializacion del thread
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" |
Alvaro13 | 2:4fa4c952883a | 4 | //activo |
jorgmassih | 0:43edf2e11fc0 | 5 | // Debbuging led |
jorgmassih | 0:43edf2e11fc0 | 6 | DigitalOut myled(LED1); |
jorgmassih | 1:741df8410d1f | 7 | // klkl |
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(); |
Alvaro13 | 4:16b60914d174 | 17 | |
Alvaro13 | 4:16b60914d174 | 18 | //Mutex |
Alvaro13 | 4:16b60914d174 | 19 | Mutex semaforo; |
Alvaro13 | 4:16b60914d174 | 20 | |
Alvaro13 | 4:16b60914d174 | 21 | //Mailbox |
Alvaro13 | 4:16b60914d174 | 22 | Mail<float, 1> mail_box; |
jorgmassih | 0:43edf2e11fc0 | 23 | |
jorgmassih | 0:43edf2e11fc0 | 24 | |
jorgmassih | 0:43edf2e11fc0 | 25 | |
jorgmassih | 0:43edf2e11fc0 | 26 | |
Alvaro13 | 4:16b60914d174 | 27 | void medicion() { |
jorgmassih | 0:43edf2e11fc0 | 28 | |
jorgmassih | 0:43edf2e11fc0 | 29 | pc.baud(9600); |
jorgmassih | 0:43edf2e11fc0 | 30 | |
jorgmassih | 0:43edf2e11fc0 | 31 | |
jorgmassih | 0:43edf2e11fc0 | 32 | |
jorgmassih | 0:43edf2e11fc0 | 33 | float acce[3]; |
jorgmassih | 0:43edf2e11fc0 | 34 | |
jorgmassih | 0:43edf2e11fc0 | 35 | mpu.setAcceleroRange(2); |
jorgmassih | 0:43edf2e11fc0 | 36 | mpu.setBW(6); |
jorgmassih | 0:43edf2e11fc0 | 37 | |
jorgmassih | 0:43edf2e11fc0 | 38 | // Test the connection |
jorgmassih | 0:43edf2e11fc0 | 39 | if (mpu.testConnection()) |
jorgmassih | 0:43edf2e11fc0 | 40 | pc.printf("MPU6050 test passed \r\n"); |
jorgmassih | 0:43edf2e11fc0 | 41 | else |
jorgmassih | 0:43edf2e11fc0 | 42 | pc.printf("MPU6050 test failed \r\n"); |
jorgmassih | 0:43edf2e11fc0 | 43 | |
jorgmassih | 0:43edf2e11fc0 | 44 | |
jorgmassih | 0:43edf2e11fc0 | 45 | float x; |
jorgmassih | 0:43edf2e11fc0 | 46 | float y; |
jorgmassih | 0:43edf2e11fc0 | 47 | |
jorgmassih | 0:43edf2e11fc0 | 48 | while(1) { |
jorgmassih | 0:43edf2e11fc0 | 49 | |
jorgmassih | 0:43edf2e11fc0 | 50 | wait(0.016); |
jorgmassih | 0:43edf2e11fc0 | 51 | mpu.getAccelero(acce); |
jorgmassih | 0:43edf2e11fc0 | 52 | |
jorgmassih | 0:43edf2e11fc0 | 53 | |
jorgmassih | 0:43edf2e11fc0 | 54 | x = (float)acce[0] / (9.81); |
jorgmassih | 0:43edf2e11fc0 | 55 | y = (float)acce[1] / (9.81); |
jorgmassih | 0:43edf2e11fc0 | 56 | |
jorgmassih | 0:43edf2e11fc0 | 57 | |
jorgmassih | 0:43edf2e11fc0 | 58 | //pc.printf("X = %f \t Y = %f \t Z = %f \r\n", x , y, z); |
jorgmassih | 0:43edf2e11fc0 | 59 | pc.printf("X = %f \t Y = %f \r\n", x , y); |
jorgmassih | 0:43edf2e11fc0 | 60 | //pc.printf("%f\r\n", x); |
jorgmassih | 0:43edf2e11fc0 | 61 | |
jorgmassih | 0:43edf2e11fc0 | 62 | } |
jorgmassih | 0:43edf2e11fc0 | 63 | } |
Alvaro13 | 4:16b60914d174 | 64 | |
Alvaro13 | 4:16b60914d174 | 65 | int main() |
Alvaro13 | 4:16b60914d174 | 66 | { |
Alvaro13 | 4:16b60914d174 | 67 | sampleAccelero.start(medicion); |
Alvaro13 | 4:16b60914d174 | 68 | } |