Hi, I am having trouble writing text to tft using the textWrite() function from the Adafruit_RA8875-master library. I need to write byte by byte from a textfile in my sd card module.
Here is my code:
String orders;
char *chr;
void writeorders()
{
test1 = SD.open("sample.txt"); //the text file contains "$location 1* $location 2* @"
if (test1)
{
Serial.println("sample.txt:");
// read from the file until there's nothing else in it:
while (test1.available())
{
orders=test1.readString();
chr = orders.c_str();
}
// close the file:
test1.close();
}
else
{
//if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
int count=0;
tft.textMode();
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(1);
tft.textSetCursor(25,150+35);
for(int h=0; h<=getLength(chr);h++)
{
Serial.print(chr);
tft.textWrite(chr);
}
}
the output from my serial is correct
but the output from my tft are garbage
but when write the whole char pointer its okay
tft.textWrite(chr);
but I really need to write it 1 character at a time. Thank you in advance
Why do you have your own function that is a duplicate of strlen()? Why did you not post it?
If the string is "Sam", the length is 3. Your loop prints the 0th, 1st, 2nd, and 3rd characters of "Sam". What is the 4th character, and how do you print a NULL?
A link to the library you are using is certainly in order.
So, when you pass it a char, instead of an array of chars, it looks in the char variable to get the address where the data is. 'd' is NOT a pointer to where a character is stored, but it is treated as one.
You should modify the library to add an overload that takes one char.