detector de sismos

Dependencies:   MMA8451Q mbed

Committer:
Jajo
Date:
Fri Feb 19 14:32:44 2016 +0000
Revision:
1:3e85b526f80f
Parent:
0:f59de0a801a5
acelero-metro biblioteca prueba 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jajo 0:f59de0a801a5 1 #include "mbed.h"
Jajo 0:f59de0a801a5 2 //Serial pc(PTE22,PTE23);
Jajo 0:f59de0a801a5 3 Serial pc(USBTX, USBRX);
Jajo 0:f59de0a801a5 4
Jajo 0:f59de0a801a5 5 #include "MMA8451Q.h"
Jajo 0:f59de0a801a5 6
Jajo 0:f59de0a801a5 7 MMA8451Q acc(PTE25, PTE24);
Jajo 0:f59de0a801a5 8 PwmOut rled(LED_RED);
Jajo 0:f59de0a801a5 9 PwmOut gled(LED_GREEN);
Jajo 0:f59de0a801a5 10 PwmOut bled(LED_BLUE);
Jajo 0:f59de0a801a5 11 int16_t dato[3];
Jajo 0:f59de0a801a5 12 int16_t x = 0;
Jajo 0:f59de0a801a5 13 int16_t y = 0;
Jajo 0:f59de0a801a5 14 int16_t z = 0;
Jajo 0:f59de0a801a5 15
Jajo 0:f59de0a801a5 16
Jajo 0:f59de0a801a5 17 DigitalOut alar(D3);
Jajo 0:f59de0a801a5 18
Jajo 0:f59de0a801a5 19
Jajo 0:f59de0a801a5 20
Jajo 0:f59de0a801a5 21
Jajo 0:f59de0a801a5 22
Jajo 0:f59de0a801a5 23
Jajo 0:f59de0a801a5 24 int main() {
Jajo 0:f59de0a801a5 25 pc.format(8,SerialBase::None,1);
Jajo 0:f59de0a801a5 26 pc.putc(65);
Jajo 0:f59de0a801a5 27
Jajo 0:f59de0a801a5 28
Jajo 0:f59de0a801a5 29
Jajo 0:f59de0a801a5 30
Jajo 0:f59de0a801a5 31 // pc.baud(9600);
Jajo 0:f59de0a801a5 32 while(1) {
Jajo 0:f59de0a801a5 33
Jajo 0:f59de0a801a5 34
Jajo 0:f59de0a801a5 35 //temblor
Jajo 0:f59de0a801a5 36 acc.getAccAllAxis(dato);
Jajo 0:f59de0a801a5 37
Jajo 0:f59de0a801a5 38 x = dato[0] * 0.03;
Jajo 0:f59de0a801a5 39 y = dato[1] * 0.03;
Jajo 0:f59de0a801a5 40 z = dato[2] * 0.03;
Jajo 0:f59de0a801a5 41
Jajo 0:f59de0a801a5 42 pc.printf("%d",dato[0]);
Jajo 0:f59de0a801a5 43 pc.printf(",");
Jajo 0:f59de0a801a5 44 pc.printf("%d",dato[1]);
Jajo 0:f59de0a801a5 45 pc.printf(",");
Jajo 0:f59de0a801a5 46 pc.printf("%d,\n",dato[2]);
Jajo 0:f59de0a801a5 47 pc.printf(",");
Jajo 0:f59de0a801a5 48
Jajo 0:f59de0a801a5 49 rled = 1.0 - abs(dato[0]/16000.0);
Jajo 0:f59de0a801a5 50 gled = 1.0 - abs(dato[1]/16000.0);
Jajo 0:f59de0a801a5 51 bled = 1.0 - abs (dato[2]/16000.0);
Jajo 0:f59de0a801a5 52 wait(.3);
Jajo 0:f59de0a801a5 53
Jajo 0:f59de0a801a5 54 if(dato[1]>=900){
Jajo 0:f59de0a801a5 55 alar=1;
Jajo 0:f59de0a801a5 56 pc.printf("* TEMBLOR");
Jajo 0:f59de0a801a5 57 wait(.2);
Jajo 0:f59de0a801a5 58 }else{
Jajo 0:f59de0a801a5 59 alar=0;
Jajo 0:f59de0a801a5 60 pc.printf("* SEGURO");
Jajo 0:f59de0a801a5 61 wait(.2);
Jajo 0:f59de0a801a5 62 }
Jajo 0:f59de0a801a5 63
Jajo 0:f59de0a801a5 64 }
Jajo 0:f59de0a801a5 65 }
Jajo 0:f59de0a801a5 66
Jajo 1:3e85b526f80f 67