.

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_09012018_copy by Calvin Kalintra

sd.h

Committer:
FranciscoSalle
Date:
2018-01-10
Revision:
6:f95438838ece
Parent:
5:8aa72ee456fc

File content as of revision 6:f95438838ece:

 #include "mbed.h"
 #include "SDBlockDevice.h"
 #include "FATFileSystem.h"
 #include "putty.h"
 #include "mbed_events.h"
 
DigitalOut redLED(PB_11), yellowLED(PB_10), greenLED(PE_15);
SDBlockDevice sd(D11, D12, D13, D10); 
EventQueue eq;
FILE* fp;
bool ejected = false; 
void takeSample()
{
    int counterb = 0;
    while (counterb <= countera) 
    {
        if (ejected == true) 
        {
            return;    
        }   
        float temp_sd = data_tempa[counterb];
        float pressure_sd = data_pressa[counterb];
        float light_sd = data_lighta[counterb];
        float date_a_sd = date_aa[counterb] ; 
        float time_a_sd = time_aa [counterb];
        float date0_a_sd = date0_aa[counterb];
        float time0_a_sd = time0_aa[counterb];
        fprintf(fp, "%i%i, %i%i, temp:%f, pressure: %f, light lvl:%f\n\r", time0_a, time_a_sd, date0_a_sd, date_a_sd, temp_sd,pressure_sd,light_sd);
        redLED = 1;
        Thread::wait(100);
        redLED = 0;
    
        if ((sw1 == 1) && (sw2 == 1)) 
        {
            fclose(fp);
            sd.deinit();
            yellowLED = 1;
            ejected = true;
        }
    }
}
 
//void sd()
//{
//    if (sd.init() != 0) {
//        printf("Init failed \n");
//        errorCode(FATAL);
//    }    
//    FATFileSystem fs("sd", &sd);
//    fp = fopen("/sd/test.txt","a");
//    if (fp == NULL) {
//        error("Could not open file for write\n");
//        errorCode(FATAL);
//    }
//    takeSample();
//   
//
//}