Printing analog pin readings to 3.2TFT

Hi,

I’m using a Mega 2560 with a 3.2TFT.

I’m using the ITDB02_Graph16.h and ITDB02_Touch.h libraries in order to use draw and touch functions. The example sketches like “Calibration” runs fine.

In order to print to the screen you use myGLCD.print("What you want to print goes here", x co-ordinates, y co-ordinates)

This works fine if you want to print a personal message but I’m trying to print a temperature reading from a analog pin to the screen. From what I understand the reading needs to be converted to a string or char before it will compile.

My code:

//Libraries
#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <avr/pgmspace.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

ITDB02        myGLCD(38,39,40,41,ITDB32S);
ITDB02_Touch  myTouch(6,5,4,3,2);

int ThermPin = 0;

void setup()
{

  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();

  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);

}
void loop()
{
  int therm;
therm=analogRead(ThermPin)-238;

myGLCD.setColor(255, 0, 0);
myGLCD.print(therm, 140, 140);

delay(1000);
}

The error I get:

Aqua_Controller.cpp: In function 'void loop()':
Aqua_Controller:29: error: invalid conversion from 'int' to 'char*'
Aqua_Controller:29: error: initializing argument 1 of 'void ITDB02::print(char*, int, int, int)'

I’ve messed around toCharArray but I’m not sure if that’s moving in the right direction.

If someone could guide me towards the correct functions (which I wll then research myself) to use to get it done I would appreciate it very much.

I don't use that library, but unless there's an "int" print method, you're stuck with either "sprintf" the value into a local character buffer, or, more simply "itoa" to a character buffer.

I would kiss you, but you're 8000km away.

Thanks! itoa working like a charm.

Thanks! itoa working like a charm.

itoa() performs an unformatted conversion from int to char array. sprintf() performs a formatted conversion.

It may not make any difference to you, but it is worth learning the differences.

For instance, if the value of the variable being printed ranges from 0 to 1023, and you'd like the string to always have 4 characters, sprintf() can do that. itoa() can not.

If you'd like to have leading 0s (0034), sprintf() can do that. itoa() can not.

If you'd like the value in hex, sprintf() can do that. itoa() can not.

If you'd like the value in hex, sprintf() can do that. itoa() can not

{{cough}}

{{cough}}

Need a cough drop while you expand on that cryptic comment?

What makes you think itoa can't convert to hex?

What makes you think itoa can't convert to hex?

It was more a failure to think...