Arturo Gasca / Mbed 2 deprecated BIOMETRICOS_HUMANOS_BETA

Dependencies:   BLE_API Definiciones Funciones HeartRate_ Hotboards_rtcc LM_35 MAX_30100 MMA8451Q Pines SDFileSystem mbed nRF51822

Fork of MAX30100_oxullo by Eduardo Avelar

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "pines.h"
00003 #include "ble/BLE.h"
00004 #include "ble/services/UARTService.h"
00005 #include "MMA8451Q.h"
00006 #include "MAX30100_PulseOximeter.h"
00007 #include "SDFileSystem.h"
00008 #include "LM35.h"
00009 #include "Hotboards_rtcc.h"
00010 #include "HeartRate.h"
00011 
00012 
00013 //////////////////////////////Definiciones BLE
00014 
00015 #define WAIT_CONECTION_TIMEOUT 20
00016 const char  *bleName = "BIOMETRICOS";
00017 BLEDevice  ble;
00018 UARTService *uartServicePtr;
00019 bool BLE_DATA_AVAILABLE = false;
00020 bool BLE_AVAILABLE =true;
00021 bool BLE_TIMEOUT = true;
00022 int BleSeconds = 0;
00023 uint8_t datosBle[20];
00024 
00025 
00026 #define NEED_CONSOLE_OUTPUT 1  /* Set this if you need debug messages on the console;
00027                                * it will have an impact on code-size and power consumption. */
00028 #if NEED_CONSOLE_OUTPUT
00029 #define DEBUG(STR) { if (uartServicePtr) uartServicePtr->write(STR, strlen(STR)); }
00030 #else
00031 #define DEBUG(...) /* nothing */
00032 #endif /* #if NEED_CONSOLE_OUTPUT */
00033 
00034 
00035 ///////////////////////////Definiciones para RTC
00036 
00037 const char *week[] = {"Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"};//days of the week
00038 const char *months[] = {"ENE","FEB","MAR","ABR","MAY","JUN", "JUL", "AGO","SEP","OCT","NOV","DIC"};//months of the year
00039 I2C device(I2C_SDA,I2C_SCL); //sda scl
00040 Hotboards_rtcc rtcc(device);
00041 
00042 
00043 //////////////////Variables de sensores para almacenamiento / envio
00044 
00045 float       Temperatura;
00046 float       RitmoCardiaco;
00047 uint16_t    Oxigeno;
00048 uint16_t    Pasos;
00049 
00050 ///////////////////////Definicion para Sensor de temperatura
00051 
00052 LM35 SensorTemp(PIN_ADC1); //PIN_ADC
00053 
00054 //////////////////////Definicion para Thermistor
00055 
00056 AnalogIn thermistor(PIN_ADC2);
00057 
00058 ///////////////////////////////////////Definicion de SD
00059 
00060 SDFileSystem sd(MOSI,MISO,SCLK,CS, "sd"); // // mosi, miso, sclk, cs, name
00061 const char* PathSensores = "/sd/LogSensores/sensores.txt";
00062 const char* PathECG = "/sd/LogSensores/ECG.txt";
00063 const char* PathAxis = "/sd/LogSensores/Axis.txt";
00064 bool archivo = true;
00065 
00066 
00067 //////////////////////////Definicion de tiempos
00068 
00069 #define REGISTER_TIME   30
00070 #define UPDATE_TIME     1
00071 int RegisterSeconds = 0;
00072 int UpdateSeconds = 0;
00073 bool SampleTime = false;
00074 //Ticker t1;
00075 //Ticker t2;
00076 
00077 
00078 /////////////////////////Definicion de sensor ECG
00079 
00080 #define MUESTRAS_ECG 100
00081 bool ECG_SAMPLE_READY = false;
00082 int ecg_idx = 0;
00083 unsigned short ecgSamples[MUESTRAS_ECG];
00084 float ecgSamples_f[MUESTRAS_ECG];
00085 HeartRate HR(ECG_OUT, ECG_LO_PLS, ECG_LO_MIN);
00086 
00087 ////////////////////Definicion de sensor RESPIRACION
00088 
00089 #define MUESTRAS_RESP 100
00090 bool RESP_SAMPLE_READY = false;
00091 int resp_idx = 0;
00092 unsigned short respSamples[MUESTRAS_RESP];
00093 float respSamples_f[MUESTRAS_RESP];
00094 
00095 ////////////////////Definicion de muestras ACELEROMETRO
00096 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00097 MMA8451Q acc(I2C_SDA, I2C_SCL, MMA8451_I2C_ADDRESS);
00098 
00099 #define MUESTRAS_AXIS 100
00100 bool AXIS_SAMPLE_READY = false;
00101 int axis_idx = 0;
00102 float axisSamples[MUESTRAS_AXIS][3]; //100 muestras, 3 ejes
00103 //float axisSamples_f[MUESTRAS_axis];
00104 
00105 
00106 // PulseOximeter is the higher level interface to the sensor
00107 // it offers:
00108 //  * beat detection reporting
00109 //  * heart rate calculation
00110 //  * SpO2 (oxidation level) calculation
00111 
00112 ///////////////////////////Definiciones  para sensor OXIMETRIA
00113 
00114 PulseOximeter pox;
00115 
00116 bool newValueMAX30100 = 0;
00117 float heartRate;
00118 float finalHeartRate;
00119 uint8_t sp02;
00120 uint16_t finalSp02;
00121 std::vector<float> valuesHeartRate;
00122 std::vector<uint8_t> valuesSp02;
00123 
00124 uint32_t REPORTING_PERIOD_MS = 1000;
00125 uint8_t samplesMAX30100 = 10;
00126 uint8_t counterMAX30100 = 0;;
00127 /////////////////////////////////////////////////////////////////
00128 
00129 Serial pc(SERIAL_TX, SERIAL_RX);
00130 
00131 DigitalOut led1(LED_R);
00132 DigitalOut led2(LED_N);
00133 
00134 
00135 
00136 
00137 
00138 
00139 FILE *fp;
00140 
00141 
00142 
00143 
00144 /////////////////////////////////////////////////////////////////////////////////////
00145 
00146 
00147 //////////////Declaracion de funciones/////////////////////////
00148 void onBeatDetected();
00149 void CadaSegundo() ;
00150 void TiempoSample();
00151 bool inicia_sd();
00152 bool setup();
00153 void do_remove(const char *fsrc);
00154 void getOxi();
00155 void getTemp();
00156 void registraSamples();
00157 void registraSensores();
00158 void getSample_ECG();
00159 void getSample_RESP();
00160 void getSample_AXIS();
00161 void write_ECG_file();
00162 void write_AXIS_file();
00163 void updateSensors ();
00164 
00165 
00166 
00167 
00168 /////////////////////////////////////////////////////
00169 
00170 
00171 
00172 
00173 void waitEvent()
00174 {
00175     if(BLE_DATA_AVAILABLE)
00176     {
00177         BLE_DATA_AVAILABLE = false;
00178         
00179         switch(datosBle[0])
00180         {
00181             case '1':   DEBUG("Recibi 1\r\n");
00182             {
00183                 break;
00184             }
00185             case '2':   DEBUG("Recibi 2\r\n");
00186             {
00187                 break;
00188             }
00189             case '3':   DEBUG("Recibi 3\r\n");
00190             {
00191                 break;
00192             }
00193             case '4':   DEBUG("Recibi 4\r\n");
00194             {
00195                 break;
00196             }
00197         }
00198         
00199     }
00200 }
00201 
00202 
00203 
00204 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
00205 {
00206     led2=0;
00207     ble.startAdvertising();
00208     BLE_AVAILABLE = false;
00209 }
00210 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
00211 {
00212     BLE_TIMEOUT = false;
00213     led2=1;
00214 }
00215 
00216 
00217 void onDataWritten(const GattWriteCallbackParams *params)
00218 {
00219     if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) {
00220         uint16_t bytesRead = params->len;
00221         pc.printf("received %u bytes\r\n", bytesRead);    
00222         
00223         for(int i=0;i<bytesRead;i++){
00224             
00225             datosBle[i] = params->data[i];
00226             
00227         }
00228         BLE_DATA_AVAILABLE = true;    
00229     }
00230 }
00231 
00232 
00233 /*
00234 void inicia_ble()
00235 {
00236     t1.attach(&CadaSegundo,1);
00237     t2.attach(&TiempoSample,0.01);
00238     pc.printf("Initialising the nRF51822\n\r");
00239     ble.init();
00240     ble.onDisconnection(disconnectionCallback);
00241     ble.onDataWritten(onDataWritten);
00242 
00243     /// setup advertising 
00244     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
00245     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
00246     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
00247                                      (const uint8_t *)bleName, strlen(bleName));
00248     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
00249                                      (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
00250 
00251     ble.setAdvertisingInterval(160); // 100ms; in multiples of 0.625ms. 
00252     ble.startAdvertising();
00253 
00254     UARTService uartService(ble);
00255     uartServicePtr = &uartService;
00256     
00257 }
00258 */
00259 
00260 void blink1(int times1, float wait1)
00261 {
00262     for(int b =0; b< times1; b++)
00263     {
00264         led1= 1;
00265         wait(wait1);
00266         led1 =0 ;
00267         wait(wait1);
00268     }
00269 }
00270 void blink2(int times2, float wait2)
00271 {
00272     for(int a =0; a< times2; a++)
00273     {
00274         led2= 1;
00275         wait(wait2);
00276         led2 =0 ;
00277         wait(wait2);
00278     }
00279 }
00280 
00281 
00282 
00283 /////////////////////////////////////////////////////////////////////////////////////
00284 
00285 
00286 int main()
00287 {
00288     
00289     pc.printf("Inicio main\n\r");
00290     blink1(4,0.1);
00291     blink2(8,0.2);
00292   
00293     //t1.attach(&CadaSegundo,1);
00294     //t2.attach(&TiempoSample,0.01);
00295     
00296     pc.printf("Initialising the nRF51822\n\r");
00297     ble.init();
00298     ble.onDisconnection(disconnectionCallback);
00299     ble.onConnection(connectionCallback);
00300     ble.onDataWritten(onDataWritten);
00301 
00302      //setup advertising 
00303     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
00304     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
00305     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
00306                                      (const uint8_t *)bleName, strlen(bleName));
00307     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
00308                                      (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
00309 
00310     ble.setAdvertisingInterval(160); // 100ms; in multiples of 0.625ms.
00311     ble.startAdvertising();
00312 
00313     UARTService uartService(ble);
00314     uartServicePtr = &uartService;
00315     
00316   
00317   
00318     
00319     //inicia_ble();
00320     
00321     if(setup())
00322         pc.printf("Sensores Inicializados\r\n");
00323     else
00324         pc.printf("Error en inicializacion\r\n");
00325     
00326     
00327     pc.printf("Inicio del programa\r\n");
00328     
00329     while(BLE_AVAILABLE)
00330     {
00331         ble.waitForEvent();
00332         waitEvent();
00333     }
00334     
00335     while(1) {
00336         updateSensors();   
00337         led1 = !led1;
00338         wait(0.2); 
00339     }
00340 
00341 
00342 }
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 // Callback (registered below) fired when a pulse is detected
00351 
00352 void onBeatDetected()
00353 {
00354 //   pc.printf("Beat!\r\n");
00355 }
00356 
00357 void CadaSegundo() //Aumenta dos contadores cada segundo para registro y actualizacion
00358 {
00359     RegisterSeconds++;
00360     UpdateSeconds++;
00361     if(BLE_TIMEOUT){
00362         BleSeconds++;
00363         pc.printf("timeout: %d\r\n",BleSeconds);
00364         if(BleSeconds == WAIT_CONECTION_TIMEOUT){
00365             BLE_AVAILABLE = false;
00366             BLE_TIMEOUT = false;
00367         }
00368         
00369     }
00370         
00371 }
00372 void TiempoSample() //Timer para samples de Ritmocardiaco,Respiracion y acelerometro
00373 {
00374     SampleTime = true;
00375 }
00376 bool inicia_sd()
00377 {  
00378     bool response;
00379     
00380   /*  fp = fopen(PathSensores, "a"); //Intento abrir el archivo... "append"
00381     if(fp == NULL) {
00382         pc.printf("No pude abrir el archivo\r\n");
00383         archivo = false;     //no existe el archivo 
00384     }
00385     else
00386     {
00387         fprintf(fp, "Dispositivo reiniciado : \r\n"); //Fue un reinicio, solo se logea
00388         pc.printf("Si existe un archivo\n");
00389         response = true;
00390     }
00391     fclose(fp); 
00392     
00393     if (!archivo)
00394     {
00395         pc.printf("Creando Carpeta de Logs\r\n");
00396         mkdir("/sd/LogSensores", 0777);
00397         fp = fopen(PathSensores, "w");
00398         if(fp == NULL) 
00399         {
00400             pc.printf("No pude abrir el archivo log %s\r\n",PathSensores); 
00401             response = false;    
00402         }
00403         else
00404         {
00405             fprintf(fp, "LOG %s creado:\r\n",PathSensores);
00406             pc.printf("Archivo %s creado por primera vez!\r\n",PathSensores);
00407             fclose(fp);
00408             wait(0.2);
00409             fp = fopen(PathECG, "w");
00410             
00411             if(fp == NULL){
00412                 pc.printf("No pude abrir el archivo log %s\r\n",PathECG); 
00413                 response = false; 
00414             }
00415             else
00416             {
00417                 fprintf(fp, "LOG %s creado:\r\n",PathECG);
00418                 pc.printf("Archivo %s creado por primera vez!\r\n",PathECG);
00419                 fclose(fp);
00420                 
00421                 wait(0.2);
00422                 fp = fopen(PathAxis, "w");
00423                 if(fp == NULL){
00424                     pc.printf("No pude abrir el archivo log %s\r\n",PathAxis);
00425                     response = false;  
00426                 }
00427                 else
00428                 {
00429                     fprintf(fp, "LOG %s creado:\r\n",PathAxis);
00430                     pc.printf("Archivo %s creado por primera vez!\r\n",PathAxis);
00431                     response = true; 
00432                 } 
00433             } 
00434             fclose(fp); 
00435         } 
00436         
00437     }*/
00438     return response;
00439 }
00440 
00441 bool setup()
00442 {
00443     
00444     pc.printf("Start program!\r\n");
00445 
00446     //incializacion SD y archivos de log
00447     inicia_sd();
00448     rtcc.begin();
00449     /* set the time (12:30:00) and date 28/nov/2016 */
00450    // rtcc.adjust( DateTime( 2016, 10, 28, 12, 30, 0) ); //year,month,day,hour,min, sec,dow
00451 
00452 
00453     // Initialize the PulseOximeter instance and register a beat-detected callback
00454     if(!pox.begin())
00455         return false;
00456     pox.setOnBeatDetectedCallback(onBeatDetected);
00457     return true;
00458 }
00459 void do_remove(const char *fsrc)
00460 {
00461     DIR *d = opendir(fsrc);
00462     struct dirent *p;
00463     char path[30] = {0};
00464     while((p = readdir(d)) != NULL) {
00465         strcpy(path, fsrc);
00466         strcat(path, "/");
00467         strcat(path, p->d_name);
00468         remove(path);
00469     }
00470     closedir(d);
00471     remove(fsrc);
00472 }
00473 
00474 void getOxi()
00475 {
00476     heartRate = pox.getHeartRate();
00477     sp02 = pox.getSpO2();
00478 
00479     if(heartRate != 0 && sp02 != 0) {
00480         pc.printf("Heart rate: %f",heartRate);
00481         pc.printf("   bpm / SpO2: %d%\r\n",sp02);
00482         valuesHeartRate.push_back(heartRate);
00483         valuesSp02.push_back(sp02);
00484         counterMAX30100 ++;
00485     } else {
00486         pc.printf("Valor Oximetria cero\r\n");
00487         Oxigeno = 0;
00488         RitmoCardiaco = 0.00;
00489         pc.printf("No finger\r\n");
00490     }
00491     if(samplesMAX30100 == counterMAX30100) {
00492 
00493         finalHeartRate = 0;
00494         finalSp02 = 0;
00495         for(int i=0; i<samplesMAX30100; i++) {
00496             finalHeartRate += valuesHeartRate[i];
00497             finalSp02 += valuesSp02[i];
00498         }
00499 
00500         finalHeartRate /= samplesMAX30100;
00501         finalSp02 /= samplesMAX30100;
00502 
00503         counterMAX30100 = 0;
00504         valuesHeartRate.clear();
00505         valuesSp02.clear();
00506         newValueMAX30100 = true;
00507     }
00508 
00509     if(newValueMAX30100) {
00510         pc.printf("Valor Oximetria valido\r\n");
00511         newValueMAX30100 = false;
00512         RitmoCardiaco = finalHeartRate;
00513         Oxigeno = finalSp02;
00514     } 
00515 }
00516 
00517 
00518 void getTemp()
00519 {
00520     Temperatura = SensorTemp.get();
00521 }
00522 
00523 
00524 void registraSamples()
00525 {
00526     //return(true);
00527 }
00528 
00529 void registraSensores()
00530 {
00531    /* pc.printf("Write sensors file\r\n");
00532     DateTime time = rtcc.now( );
00533     pc.printf("%d:%d:%d,%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00534                 time.day( ),months[time.month( )],time.year());
00535     /*fp = fopen("/sd/LogSensores/sensores.txt", "a"); //"a" append
00536     if(fp == NULL) {
00537         pc.printf("No pude abrir! :(\r\n");
00538         return(false);
00539     } else {
00540         DateTime time = rtcc.now( );
00541         fprintf(fp,"T=%.2f,O=%d,RC=%.2f,P=%d,",Temperatura,Oxigeno,RitmoCardiaco,Pasos);
00542         fprintf(fp,"H=%d:%d:%d,F=%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00543                 time.day( ),months[time.month( )],time.year());
00544         fclose(fp);
00545 
00546         pc.printf("Escribi en SD! :D \r\n");
00547         pc.printf("T=%.2f,O=%d,RC=%.2f,P=%d,",Temperatura,Oxigeno,RitmoCardiaco,Pasos);
00548         pc.printf("H=%d:%d:%d,F=%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00549                 time.day( ),months[time.month( )],time.year());
00550         return(true);
00551     }*/
00552 }
00553 void getSample_ECG()
00554 {
00555     if(HR.available())
00556     {
00557         ecgSamples[ecg_idx++] = HR.read();
00558     }
00559     else
00560     {
00561         ecgSamples[ecg_idx++] = 0;
00562     }
00563     if(ecg_idx == MUESTRAS_ECG)
00564     {
00565         ecg_idx =0;
00566         ECG_SAMPLE_READY = true;
00567     }
00568     
00569 }
00570 
00571 void getSample_RESP()
00572 {
00573     respSamples[resp_idx++] = thermistor.read_u16();
00574     
00575     if (resp_idx == MUESTRAS_RESP)
00576     {
00577         resp_idx = 0;
00578         RESP_SAMPLE_READY = true;
00579     }
00580 }
00581 
00582 void getSample_AXIS()
00583 {
00584     float x, y, z;
00585     x = abs(acc.getAccX());
00586     y = abs(acc.getAccY());
00587     z = abs(acc.getAccZ());
00588     
00589     axisSamples[axis_idx][0] = x;
00590     axisSamples[axis_idx][1] = y;
00591     axisSamples[axis_idx][2] = z;
00592     
00593     axis_idx++;
00594     
00595     if (axis_idx == MUESTRAS_AXIS)
00596     {
00597         axis_idx = 0;
00598         AXIS_SAMPLE_READY = true;
00599     }
00600 }
00601 
00602 void write_ECG_file()
00603 {
00604    bool response;
00605    /*pc.printf("Write ECG file\r\n");
00606    DateTime time = rtcc.now( );
00607     pc.printf("%d:%d:%d,%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00608                 time.day( ),months[time.month( )],time.year());
00609     /*if(true)
00610     {
00611         fp = fopen(PathECG, "a"); //"a" append
00612         if(fp == NULL) 
00613         {
00614             pc.printf("No pude abrir! :(\r\n");
00615             response =false;
00616         } 
00617         else 
00618         { 
00619             DateTime time = rtcc.now( );
00620             fprintf(fp,"%d:%d:%d,%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00621                     time.day( ),months[time.month( )],time.year());
00622             
00623             for (int i =0; i< MUESTRAS_ECG; i++)
00624             {
00625                 fprintf(fp,"%d",ecgSamples[i]);
00626             }
00627         
00628             pc.printf("Escribi en SD! :D \r\n");
00629             response = true;
00630             
00631         }
00632         fclose(fp);
00633     }*/
00634     //return response;
00635     
00636 }
00637 
00638 void write_AXIS_file()
00639 {
00640     bool response;
00641    /* pc.printf("Write axis file\r\n");
00642     DateTime time = rtcc.now( );
00643     pc.printf("%d:%d:%d,%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00644                 time.day( ),months[time.month( )],time.year());
00645    /* fp = fopen(PathAxis, "a"); //"a" append
00646     if(fp == NULL) 
00647     {
00648         pc.printf("No pude abrir! :(\r\n");
00649         response = false;
00650     } 
00651     else 
00652     { 
00653         DateTime time = rtcc.now( );
00654         fprintf(fp,"%d:%d:%d,%d/%s/%d\r\n",time.hour( ),time.minute( ),time.second( ),
00655                 time.day( ),months[time.month( )],time.year());
00656         
00657         for (int i =0; i< MUESTRAS_AXIS; i++)
00658         {  
00659             fprintf(fp,"%1.2f,%1.2f,%1.2f",axisSamples[0][i],axisSamples[1][i],axisSamples[2][i]);
00660         }
00661     
00662         pc.printf("Escribi en SD! :D \r\n");
00663         response = true;
00664     }
00665     fclose(fp);*/
00666     //return response;
00667 }
00668 
00669 
00670 
00671 void updateSensors ()
00672 {
00673     // Make sure to call update as fast as possible
00674     pox.update();
00675     
00676     //<-Get Step Accel
00677 
00678     if(SampleTime){ 
00679         //cuando se cumpla el tiempo...obtener 1 muestra y aumentar contador
00680         //getSample ECG
00681         //getSample Respiracion
00682         //getSample Axis
00683         
00684         getSample_ECG();
00685         getSample_RESP();
00686         getSample_AXIS();   
00687         SampleTime = false;
00688     }
00689     if (ECG_SAMPLE_READY)
00690     {
00691         ECG_SAMPLE_READY = false;
00692         write_ECG_file();
00693         //escribir todas las muestras en SD y borrar contador
00694     }
00695     if (AXIS_SAMPLE_READY)
00696     {
00697         AXIS_SAMPLE_READY = false;
00698         write_AXIS_file();
00699         //escribir todas las muestras en SD y borrar contador
00700     }
00701     if (RESP_SAMPLE_READY);
00702     {
00703         RESP_SAMPLE_READY = false;
00704         //Analisis de datos para deteccion de picos
00705         //escribir todas lasmuestras en SD y borrar contador
00706     }  
00707     if (UpdateSeconds >= UPDATE_TIME) { //Si ya paso el tiempo definido en UPDATE_TIME
00708         getOxi();
00709         getTemp();
00710         UpdateSeconds = 0;
00711     }
00712     if (RegisterSeconds >= REGISTER_TIME) { //Si ya paso el tiempo definido en REGISTER_TIME
00713 
00714         registraSensores();
00715         RegisterSeconds = 0;
00716     }
00717 }