mirror of
https://gitlab.com/lander-team/static-load-test-code.git
synced 2025-08-02 03:21:25 +00:00
writing every loop
This commit is contained in:
56
src/main.cpp
56
src/main.cpp
@@ -11,6 +11,7 @@ HX711 lc2;
|
|||||||
HX711 lc3;
|
HX711 lc3;
|
||||||
|
|
||||||
void write2CSV(struct LoadCells &);
|
void write2CSV(struct LoadCells &);
|
||||||
|
void closeFile();
|
||||||
void initFile();
|
void initFile();
|
||||||
|
|
||||||
void read_lc0();
|
void read_lc0();
|
||||||
@@ -27,7 +28,9 @@ const int pin_lc3 = 20;
|
|||||||
const int chipSelect = BUILTIN_SDCARD;
|
const int chipSelect = BUILTIN_SDCARD;
|
||||||
File dataFile;
|
File dataFile;
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
pinMode(lc_clock, INPUT);
|
pinMode(lc_clock, INPUT);
|
||||||
|
|
||||||
@@ -71,7 +74,11 @@ void setup() {
|
|||||||
State.lc3 = lc3.get_value();
|
State.lc3 = lc3.get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
|
dataFile = SD.open("loadCell.csv", FILE_WRITE);
|
||||||
|
dataFile.seek(EOF);
|
||||||
|
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
// write2CSV(State);
|
// write2CSV(State);
|
||||||
// delay(20);
|
// delay(20);
|
||||||
@@ -86,7 +93,8 @@ void read_lc1() { State.lc1 = lc1.get_value(); }
|
|||||||
void read_lc2() { State.lc2 = lc2.get_value(); }
|
void read_lc2() { State.lc2 = lc2.get_value(); }
|
||||||
void read_lc3() { State.lc3 = lc3.get_value(); }
|
void read_lc3() { State.lc3 = lc3.get_value(); }
|
||||||
|
|
||||||
void write2CSV(LoadCells &State) {
|
void write2CSV(LoadCells &State)
|
||||||
|
{
|
||||||
|
|
||||||
dataFile.print(String(State.lc0, 5));
|
dataFile.print(String(State.lc0, 5));
|
||||||
dataFile.print(",");
|
dataFile.print(",");
|
||||||
@@ -99,10 +107,12 @@ void write2CSV(LoadCells &State) {
|
|||||||
dataFile.close();
|
dataFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initFile() {
|
void initFile()
|
||||||
|
{
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
// see if the card is present and can be initialized:
|
// see if the card is present and can be initialized:
|
||||||
if (!SD.begin(chipSelect)) {
|
if (!SD.begin(chipSelect))
|
||||||
|
{
|
||||||
Serial.println("Card failed, or not present. \n\nABORTING SIMULATION");
|
Serial.println("Card failed, or not present. \n\nABORTING SIMULATION");
|
||||||
}
|
}
|
||||||
Serial.println("Card initialized.");
|
Serial.println("Card initialized.");
|
||||||
@@ -110,37 +120,49 @@ void initFile() {
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
const char *fileName;
|
const char *fileName;
|
||||||
|
|
||||||
if (SD.exists("loadCell.csv")) {
|
if (SD.exists("loadCell.csv"))
|
||||||
while (i > 0.0) {
|
{
|
||||||
|
while (i > 0.0)
|
||||||
|
{
|
||||||
fileName = ("loadCell_" + String(i) + ".csv").c_str();
|
fileName = ("loadCell_" + String(i) + ".csv").c_str();
|
||||||
|
|
||||||
if (!SD.exists(fileName)) {
|
if (!SD.exists(fileName))
|
||||||
|
{
|
||||||
// Open simOut_i.csv
|
// Open simOut_i.csv
|
||||||
dataFile = SD.open(fileName, FILE_WRITE);
|
dataFile = SD.open(fileName, FILE_WRITE);
|
||||||
|
|
||||||
if (dataFile) {
|
if (dataFile)
|
||||||
|
{
|
||||||
Serial.println("File successfully opened!");
|
Serial.println("File successfully opened!");
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
// if the file didn't open, print an error:
|
// if the file didn't open, print an error:
|
||||||
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
||||||
}
|
}
|
||||||
i = 0.0;
|
i = 0.0;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Open simOut.csv
|
// Open simOut.csv
|
||||||
dataFile = SD.open("simOut.csv", FILE_WRITE);
|
dataFile = SD.open("simOut.csv", FILE_WRITE);
|
||||||
if (dataFile) {
|
if (dataFile)
|
||||||
|
{
|
||||||
Serial.println("File successfully opened!");
|
Serial.println("File successfully opened!");
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
// if the file didn't open, print an error:
|
// if the file didn't open, print an error:
|
||||||
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataFile.println("lc0,lc1,lc2,lc3");
|
dataFile.println("lc0,lc1,lc2,lc3");
|
||||||
|
|
||||||
|
dataFile.close();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user