el prollecto trata del detector de las vibraciones de un motor alejandro mejia garcia jorge arturo juarez ornelas
main.cpp@13:0d56aff123d4, 2016-02-12 (annotated)
- Committer:
- Jajo
- Date:
- Fri Feb 12 13:35:29 2016 +0000
- Revision:
- 13:0d56aff123d4
- Parent:
- 12:985489f212d0
- Child:
- 14:93d715bd49a7
checa el rango de vibraci?n
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jajo | 0:f4790997ab47 | 1 | #include "mbed.h" |
Jajo | 0:f4790997ab47 | 2 | |
Jajo | 0:f4790997ab47 | 3 | #include "MMA8451Q.h" |
Jajo | 0:f4790997ab47 | 4 | |
Jajo | 0:f4790997ab47 | 5 | MMA8451Q acc(PTE25, PTE24); |
Jajo | 0:f4790997ab47 | 6 | PwmOut rled(LED_RED); |
Jajo | 0:f4790997ab47 | 7 | PwmOut gled(LED_GREEN); |
Jajo | 0:f4790997ab47 | 8 | PwmOut bled(LED_BLUE); |
Jajo | 0:f4790997ab47 | 9 | int16_t dato[3]; |
Jajo | 0:f4790997ab47 | 10 | int16_t x = 0; |
Jajo | 12:985489f212d0 | 11 | int16_t y = 0; |
Jamg | 5:943404b2e562 | 12 | |
Jajo | 0:f4790997ab47 | 13 | int16_t z = 0; |
Jajo | 0:f4790997ab47 | 14 | |
Jajo | 0:f4790997ab47 | 15 | int main() { |
Jajo | 0:f4790997ab47 | 16 | |
Jajo | 0:f4790997ab47 | 17 | |
Jajo | 0:f4790997ab47 | 18 | |
Jajo | 0:f4790997ab47 | 19 | |
Jajo | 0:f4790997ab47 | 20 | while(1) { |
Jajo | 0:f4790997ab47 | 21 | |
Jajo | 0:f4790997ab47 | 22 | |
Jajo | 0:f4790997ab47 | 23 | //temblor |
Jajo | 0:f4790997ab47 | 24 | acc.getAccAllAxis(dato); |
Jajo | 0:f4790997ab47 | 25 | |
Jajo | 0:f4790997ab47 | 26 | x = dato[0] * 0.03; |
Jajo | 0:f4790997ab47 | 27 | y = dato[1] * 0.03; |
Jajo | 0:f4790997ab47 | 28 | z = dato[2] * 0.03; |
Jajo | 0:f4790997ab47 | 29 | |
Jajo | 0:f4790997ab47 | 30 | // gir.printf("%d",dato[0]); |
Jajo | 0:f4790997ab47 | 31 | //gir.printf(","); |
Jajo | 0:f4790997ab47 | 32 | // gir.printf("%d",dato[1]); |
Jajo | 0:f4790997ab47 | 33 | // gir.printf(","); |
Jajo | 0:f4790997ab47 | 34 | //gir.printf("%d,\n",dato[2]); |
Jajo | 0:f4790997ab47 | 35 | // gir.printf(","); |
Jajo | 0:f4790997ab47 | 36 | |
Jajo | 0:f4790997ab47 | 37 | // rled = 1.0 - abs(dato[0]/16000.0); |
Jajo | 0:f4790997ab47 | 38 | // gled = 1.0 - abs(dato[1]/16000.0); |
Jajo | 0:f4790997ab47 | 39 | //bled = 1.0 - abs (dato[2]/16000.0); |
Jajo | 0:f4790997ab47 | 40 | // wait(.3); |
Jajo | 0:f4790997ab47 | 41 | |
Jajo | 13:0d56aff123d4 | 42 | if(dato[0]<=-200){ |
Jajo | 0:f4790997ab47 | 43 | rled=0; |
Jajo | 12:985489f212d0 | 44 | |
Jajo | 13:0d56aff123d4 | 45 | wait(.2); |
Jajo | 0:f4790997ab47 | 46 | |
Jajo | 0:f4790997ab47 | 47 | rled=1; |
Jajo | 0:f4790997ab47 | 48 | }else{ |
Jajo | 0:f4790997ab47 | 49 | bled=1; |
Jajo | 0:f4790997ab47 | 50 | gled=0; |
Jajo | 12:985489f212d0 | 51 | |
Jajo | 13:0d56aff123d4 | 52 | wait(.2); |
Jajo | 0:f4790997ab47 | 53 | gled=1; |
Jajo | 0:f4790997ab47 | 54 | } |
Jajo | 0:f4790997ab47 | 55 | |
Jajo | 13:0d56aff123d4 | 56 | |
Jajo | 13:0d56aff123d4 | 57 | if(dato[1]>=350){ |
Jajo | 13:0d56aff123d4 | 58 | bled=1; |
Jajo | 13:0d56aff123d4 | 59 | rled=0; |
Jajo | 13:0d56aff123d4 | 60 | |
Jajo | 13:0d56aff123d4 | 61 | wait(.2); |
Jajo | 13:0d56aff123d4 | 62 | |
Jajo | 13:0d56aff123d4 | 63 | rled=1; |
Jajo | 13:0d56aff123d4 | 64 | }else{ |
Jajo | 13:0d56aff123d4 | 65 | bled=1; |
Jajo | 13:0d56aff123d4 | 66 | gled=0; |
Jajo | 13:0d56aff123d4 | 67 | |
Jajo | 13:0d56aff123d4 | 68 | wait(.2); |
Jajo | 13:0d56aff123d4 | 69 | gled=1; |
Jajo | 13:0d56aff123d4 | 70 | } |
Jajo | 0:f4790997ab47 | 71 | |
Jajo | 13:0d56aff123d4 | 72 | if(dato[2]<=16200){ |
Jajo | 13:0d56aff123d4 | 73 | bled=1; |
Jajo | 13:0d56aff123d4 | 74 | rled=0; |
Jajo | 13:0d56aff123d4 | 75 | |
Jajo | 13:0d56aff123d4 | 76 | wait(.2); |
Jajo | 13:0d56aff123d4 | 77 | |
Jajo | 13:0d56aff123d4 | 78 | rled=1; |
Jajo | 13:0d56aff123d4 | 79 | }else{ |
Jajo | 13:0d56aff123d4 | 80 | bled=1; |
Jajo | 13:0d56aff123d4 | 81 | gled=0; |
Jajo | 13:0d56aff123d4 | 82 | |
Jajo | 13:0d56aff123d4 | 83 | wait(.2); |
Jajo | 13:0d56aff123d4 | 84 | gled=1; |
Jajo | 13:0d56aff123d4 | 85 | } |
Jajo | 0:f4790997ab47 | 86 | |
Jajo | 0:f4790997ab47 | 87 | |
Jajo | 0:f4790997ab47 | 88 | |
Jajo | 0:f4790997ab47 | 89 | } |
Jajo | 0:f4790997ab47 | 90 | } |
Jamg | 2:f671e524d19c | 91 | //Hola// |