I am trying to serial print/ read 16 characters at a time for my LCD from SD card.
With the push of a button, the LCD will display 16 characters at a time. I am not sure how to go about, String? char Array?
Example: the text "The quick brown fox jumps over the lazy dog" exists in a txt file.
When i push a button, it displays
"the quick brown"
And i push it again, it displays
"fox jumps over t"
And i push it again, it displays
"he lazy dog"
The problem with string and char array is that the memory allocation and array size limited by the hardware. The txt file may contain a million characters or so. I am sure there is another way to do it.
LCD code not included, I know how to do that part.
#include <SPI.h>
#include <SD.h>
File myFile;
int button1 5;
void setup() {
Serial.begin(9600);
while (!Serial) {
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
pinMode(button1, INPUT_PULLUP);
}
void loop() {
int buttonstate = 0;
int buttonstate = digitalRead(button1);
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
if (buttonstate = 1) {
Serial.write(myFile.read());
}
myFile.close();
}
}