diff --git a/firmware/v01/v01.ino b/firmware/v01/v01.ino index 51086c1..29aa5b5 100644 --- a/firmware/v01/v01.ino +++ b/firmware/v01/v01.ino @@ -42,16 +42,20 @@ File myFile; #define sd_not_in 0 // SD card is not inserted #define sd_in 1 // SD card is inserted #define file_fail 2 // Can't write to file +#define writing 3 // Write on the sd card #define load_off 0 // Turn off the load #define load_on 1 // Turn on the load #define off 0 // off is always zero #define on 1 // on is always one +#define no 0 // no is always zero +#define yes 1 // yes is alyays one //---------------------------------------------------------------- // Variables -------------------------------------------------------------------------------------------------------------- bool sd_rw = off; // Holds the state of read/write of the card bool load_status = load_off; // Holds the state of on/off of the load +bool sd_inserted = no; // Holds the stats if sd card is in or not int sd_status = sd_not_in; // Holds information about the sd card int currentScreen = 0; // Current display menu @@ -62,7 +66,7 @@ String screens[numOfScreens][2] = {{"Voltage 1","Volts"}, {"Voltage 2","Volts"}, String parameters_sd[2] = {"No","Yes"}; // String to display the sd card logging String parameters_load[2] = {"Off","On"}; // String to display the load state -String sd_card[3] = {"Card missing","Card inserted","File Write fail"}; // String to display the sd card state +String sd_card[4] = {"Card missing","Card inserted","File Write fail","Writing..."}; // String to display the sd card state float parameters[4]; // Parameters of the several voltages and current float denominator; @@ -108,10 +112,12 @@ void setup() if (SD.begin()) // Initiate SD card { - sd_status = sd_in; // If sd card is initiated successfully change variable status to sd_in + sd_status = sd_in; // If sd card is initiated successfully change variable sd_in + sd_inserted = yes; // and change variable sd_inserted to yes } else { - sd_status = sd_not_in; // If sd card is not initiated change variable status to sd_not_in + sd_status = sd_not_in; // If sd card is not initiated change variable to sd_not_in + sd_inserted = no; // and change variable sd_inserted to no } } @@ -132,22 +138,35 @@ void loop() parameters[voltage_2] = volt_pin(volt_2); // Update voltage two value - if (sd_rw == on) // If sd_rw value is turned on + if (sd_inserted == no) // If sd_rw value is turned on + { + sd_status = sd_not_in; + } + else if (sd_rw == on) { myFile = SD.open("measure.txt", FILE_WRITE); // Open file measure.txt for writing if (myFile) // if succeds { + myFile.print("Batt voltage, "); myFile.println(volt_pin(v_batt)); // Write to card battery voltage + myFile.print("Voltage one, "); myFile.println(volt_pin(volt_1)); // Write to card voltage one + myFile.print("Voltage two, "); myFile.println(volt_pin(volt_2)); // Write to card voltage two myFile.println(""); // Write to card an empty line myFile.close(); // Close file + sd_status = writing; } else { - sd_status = file_fail; // + sd_status = file_fail; } } + else + { + sd_status = sd_in; + } + printScreen(); // Refresh screen and print current menu and values delay(5000); // Repeat the main loop every 5 seconds }