Hello!
I need to convert a string variable in length floats in order to generate a graph of temperature.
You must separate values from buf [ i ] in groups of 5 bytes and then convert them to floats.
Once this is done the output values must meet the conditions required for the chart is drawn correctly on my LCD.
Here's the code I'm trying to write:
I am using the library sdfat.h.
void tempgScreen()
{
int x, y, z;
int grafico;
t = rtc.getTime();
int16_t n;
uint8_t buf[6];
float temperatura;
file.open(&root, "LOGTDIA.TXT", O_READ);
while ((n = file.read(buf, sizeof(buf))) > 0)
{
for (uint8_t i = 0; i < n; i++)
buf[ i ] // separate values from buf [ i ] in groups of 5 bytes and then convert them to floats
}
temperatura = // Float of buf[ i ] //
if ((temperatura) < 22.5)
{
grafico = 190;
}
else if ((temperatura) >27.5)
{
grafico =30;
}
else
{
grafico = (190-((temperatura-22.5)*30));
}
for (uint8_t j=0; j < (n/5) ;j++)
{
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.drawPixel((40+j),grafico);
}
}
Here is the code that writes the values ??in the SD card:
//Write CR LF to a file
void writeCRLF(SdFile& f) {
f.write((uint8_t*)"\r\n", 2);
}
void logtempgraf() //Grava dados no SD CARD para gerar grafico de temperatura.
{
t= rtc.getTime();
String oldminuto;
oldminuto = time;
time = t.min;
if (oldminuto != time)
{
file.open(&root, "LOGTDIA.TXT", O_CREAT | O_APPEND | O_WRITE);
if ((tempC<=0.0) || (tempC>99.9))
{
file.print("00.00");
writeCRLF(file);
}
else
{
file.print(tempC);
writeCRLF(file);
}
file.close();
if ((t.hour==23) && (t.min==59))
{
file.remove(file,"LOGTDIA.TXT");
}
}
}
Here is a picture of how information is stored in TXT and the screen where the graphic will show.
Sorry for English I'm using google translator.
Thank you.
Moderator edit: CODE TAGS