Hello everyone I'm going to do my best to explain the issue I'm having.
Currently I'm building a chess board that will allows the user to import a new chess puzzle in a .csv file format. which looks like this
8 WK
7 WP WP
6 WP BB QW
5 WP
4 WP
3 BP BB BP
2 BP WR WR BP
1 BK BR BP
a b c d e f g h
I need to mapp the above chess board to induvial LEDs to light up each spot that would need a piece to be placed on and then to 8 mux channels so I can tell if a piece is in the right spot. After the user puts the right pieces on the right spots I will also check to see if there is a piece in the right spot, and then clear all LEDs and tell the user which color he/she is playing.
The user will use a pot to select which puzzle he/she would like to do and then the program will open that said file. I have that part done but Can't seem to find how to record the cells to a array variable.
I found this code online but can't really use it b/c I don't understand it. Can someone explain to me what this code is doing?
Here is my sdcard.cpp file which reads and is working for me.
Here is the code that I found on https://forum.arduino.cc/index.php?topic=210904.0
I will do my best to explain the code below. I will use the // and write each line to what I think it is doing.
That is about all I can do with my current knowledge.
Thank you for taking the time out of your day to help me learning.
Joe
Currently I'm building a chess board that will allows the user to import a new chess puzzle in a .csv file format. which looks like this
8 WK
7 WP WP
6 WP BB QW
5 WP
4 WP
3 BP BB BP
2 BP WR WR BP
1 BK BR BP
a b c d e f g h
I need to mapp the above chess board to induvial LEDs to light up each spot that would need a piece to be placed on and then to 8 mux channels so I can tell if a piece is in the right spot. After the user puts the right pieces on the right spots I will also check to see if there is a piece in the right spot, and then clear all LEDs and tell the user which color he/she is playing.
The user will use a pot to select which puzzle he/she would like to do and then the program will open that said file. I have that part done but Can't seem to find how to record the cells to a array variable.
I found this code online but can't really use it b/c I don't understand it. Can someone explain to me what this code is doing?
Here is my sdcard.cpp file which reads and is working for me.
Code:
void SDcard::open_file(int indexer)
{
filename_index = indexer;
if (!SD.begin(chipSelect))
{
while (true);
}
File dataFile = SD.open(str_puzzle_name[filename_index]); //opening File T015704.csv
// if the file is available, write to it:
if (dataFile)
{
while (dataFile.available())
{
Serial.write(dataFile.read());
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else
{
Serial.println("error opening file");
}
} // end openfile
Here is the code that I found on https://forum.arduino.cc/index.php?topic=210904.0
I will do my best to explain the code below. I will use the // and write each line to what I think it is doing.
Code:
char buffer[40]; // defining an array with input being 40 char long
byte index = 0; // defining a variable called index and setting it to 0
while (myFile.available())
{
char c = myFile.read(); // defining char c to equal the file you want to read
if(c == '\n' || c == '\r')
{
parseAndSave(buffer);
index = 0;
buffer[index] = '\0';
}
else
{
buffer[index++] = c;
buffer[index] = '\0';
}
}
That is about all I can do with my current knowledge.
Thank you for taking the time out of your day to help me learning.
Joe