Go Down

Topic: ILI9341(new)SPI library for Due supporting DMA transfer(Uno, Mega,.. compatible) (Read 173033 times) previous topic - next topic


From ILI9341_due.h
Code: [Select]

virtual size_t print(double, int = 2);

So you can just say:
Code: [Select]

     tft.print(1.2345, 1);

In exactly the same way that you would say Serial.print(1.2345, 1);

The library lets you align text however you want.
Of course you can format your float expressions with dtostrf() into a char buffer in the normal.   Then print the buffer with all the facilities provided by Marek.



Not too familiar with  your suggestion but I redid my sketch using Sprintf and TFT.printAt to comply with the library demands as in the arcs.ino example and I was able to succeed with a 3 digit integer value but the int always displays a "?" instead of the real value.

Sketch is over 700 lines so here's some details below

Serial data:
avgwindspeed varies from 0-99.9
avgwindangle varies from 0-360

float avgwindspeed ;

int avgwindangle ;

char textBuff [20];

void loop();

sprintf(textBuff, "%4.1f", avgwindspeed);
tft.printAt(textBuff, 260, 23);

sprintf(textBuff, "%3d", avgwindangle);
tft.printAt(textBuff, 260, 80);

Any ideas why ?

Once this is resolved then padding needs to be arranged.



Arduino started off on a small AVR.    It supports f-p printing with C++ classes.    You can specify how many decimal places but not the overall format width.    (it defaults to 2 dec places)

Although you have access to the regular C library,  printf() defaults to the cut-price version.     Formatting f-p expressions is quite expensive.   That is why you see "?" when you try to use "%f"

Code: [Select]

#if defined(__arm__)        //e.g. Zero, Due, STM32
#include <avr/dtostrf.h>

void setup()
    Serial.println("print Floating Point on Arduino");
    Serial.print("regular Serial.print(1.234) ");
    char buf[40];
    Serial.print("sprintf(2.345) ");
    sprintf(buf, "%5.2f", 2.345);
    Serial.print("dtostrf(3.456) ");
    dtostrf(3.456, 5, 2, buf);

void loop()

Note that some Arduino "cores" expect you to include "dtostrf.h"
But the standard AVR IDE always knows about dtostrf()

Cores like ARM, ESP32, ESP8266 come with a full-fat printf() so you can use %f easily.
If you want to use a Uno, Mega, ... you will need dtostrf()

dtostrf() can format output nicely
Arduino print() can never pad expressions.   Everyone has discovered how nasty integer and hex numbers look.



Thanks David got it displaying all values now. I read somewhere that it would provide text padding as well but it does not seem to be the case so I'm using TFT.fillRect for padding.


Go Up