diff --git a/firmware/v01/v01.ino b/firmware/v01/v01.ino index 32bb033..e1185d3 100644 --- a/firmware/v01/v01.ino +++ b/firmware/v01/v01.ino @@ -54,8 +54,8 @@ SoftwareSerial mySerial(BLUE_RX, BLUE_TX); // Start file descriptor and assign p // Macros -------------------------------------------------------- -#define rLEFT digitalRead(LEFT) // Read button Left -#define rRIGHT digitalRead(RIGHT) // Read button Right +#define rLEFT digitalRead(LEFT) // Read button Left +#define rRIGHT digitalRead(RIGHT) // Read button Right #define rACT digitalRead(ACT) // Read button Action //---------------------------------------------------------------- @@ -141,48 +141,45 @@ void setup() // Timer compare interrupt service routine -- ISR(TIMER1_COMPA_vect) { - menuState(); // Read buttons act accordingly and update menus - if (amp_pin(i_load) > curr_limit) // If load current more then current limit + menuState(); // Read buttons act accordingly and update menus + if (amp_pin(i_load) > curr_limit) // If load current more then current limit { - load_status = off; // Turn off load + load_status = off; // Turn off load } digitalWrite(load_line, load_status); // Turn load on or off depending on the load_status - - - if (mySerial.available()) { - ble_data = mySerial.read(); -// Serial.write(mySerial.read()); // For debug only - switch(ble_data) + if (mySerial.available()) { // If there is incoming serial data + ble_data = mySerial.read(); // save it caracter into ble_data + switch(ble_data) // Evaluate caracter { - case 'a': - dtostrf(parameters[battery_volt], 5, 2, outstr); - mySerial.write(outstr); - break; - - case 'b': - dtostrf(parameters[voltage_1], 5, 2, outstr); - mySerial.write(outstr); - break; - - case 'c': - dtostrf(parameters[voltage_2], 5, 2, outstr); - mySerial.write(outstr); - break; + case 'a': // If caracter is 'a' + dtostrf(parameters[battery_volt], 5, 2, outstr); // convert battery voltage to string + mySerial.write(outstr); // and send it to bluetooth + break; // finish switch statment - case 'd': - dtostrf(parameters[curr], 5, 2, outstr); - mySerial.write(outstr); - break; + case 'b': // If caracter is 'b' + dtostrf(parameters[voltage_1], 5, 2, outstr); // convert voltage 1 to string + mySerial.write(outstr); // and send it to bluetooth + break; // finish switch statment - case 'e': - load_status = on; - break; - - case 'f': - load_status = off; - break; + case 'c': // If caracter is 'c' + dtostrf(parameters[voltage_2], 5, 2, outstr); // convert voltage 2 to string + mySerial.write(outstr); // and send it to bluetooth + break; // finish switch statment + + case 'd': // If caracter is 'd' + dtostrf(parameters[curr], 5, 2, outstr); // convert load current to string + mySerial.write(outstr); // and send it to bluetooth + break; // finish switch statment + + case 'e': // If caracter is 'd' + load_status = on; // turn ON load + break; // finish switch statment + + case 'f': // If caracter is 'f' + load_status = off; // turn OFF load + break; // finish switch statment } } } @@ -196,8 +193,8 @@ void loop() parameters[voltage_2] = volt_pin(volt_2); // Update voltage two value parameters[curr] = amp_pin(i_load); // Update current load - - + + if (sd_inserted == no) // If SD card is not inserted { @@ -205,7 +202,7 @@ void loop() } else if (sd_rw == on) // otherwise sd_rw is ON { - myFile = SD.open(file_name + ".TXT", FILE_WRITE); // Open file name and add ".TXT", + myFile = SD.open(file_name + ".TXT", FILE_WRITE); // Open file name and add ".TXT", // for writing if (myFile) // if succeds {