Hi i would like to ask for some assistance with my personal project.
Here is the scenario I want to read a line from the text file inside the SD card I manage read all the lines inside the text file but I cant search the exact text inside the text file.
Here is my expected output :
Initializing SD card...initialization done.
test.txt:
FIDenomStart
FIDenomEnd
and here is my code using carriage return and its output is :
Initializing SD card...initialization done.
test.txt:
FIDenomStart
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
int FiDenomCount;
int FIDenomStart;
int FIDenomEnd;
File myFile;
int recNum = 0;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
}
Serial.print("Initializing SD card...");
if (!SD.begin(53))
{
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("test.txt");
if (myFile)
{
Serial.println("test.txt:");
while (myFile.available())
{
String list = myFile.readStringUntil('\r');
recNum++;
// Serial.println(list + " " + recNum);
if (list == "1stDenEnd")
{
FIDenomEnd = recNum;
Serial.println("FIDenomEnd");
}
if (list == "1stDenStart")
{
FIDenomStart = recNum;
Serial.println("FIDenomStart");
}
}
}
}
void loop() {
// nothing happens after setup
}
and here is my other code using line feed and its output :
Initializing SD card...initialization done.
test.txt:
FIDenomEnd
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
int FiDenomCount;
int FIDenomStart;
int FIDenomEnd;
File myFile;
int recNum = 0;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
}
Serial.print("Initializing SD card...");
if (!SD.begin(53))
{
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("test.txt");
if (myFile)
{
Serial.println("test.txt:");
while (myFile.available())
{
String list = myFile.readStringUntil('\n');
recNum++;
// Serial.println(list + " " + recNum);
if (list == "1stDenEnd")
{
FIDenomEnd = recNum;
Serial.println("FIDenomEnd");
}
if (list == "1stDenStart")
{
FIDenomStart = recNum;
Serial.println("FIDenomStart");
}
}
}
}
void loop() {
// nothing happens after setup
}