Volt Ampmeter

Hello All,

I have a Arduino-Mega and the tft seeedstudio 2.8.
And the library for Arduino
I try to make a volt-amp meter 0-300v 100ma
All is working wel, only the display gives a question mark by reading the output off a sensorValue.
This is an example.

void loop(){
int sensorValue = analogRead(A6);
float voltage_string = sensorValue * (5.0 / 1023.0);
char inChar=voltage_string;
Tft.drawChar(inChar,226,125,2,RED);
Serial.println(voltage_string);

The reading by Serialprint is ok

Can anyone help me.

Thanks

You dont draw a number. You draw a char.
Take correct variable types and print routines

Hello Rony,

Can you give me an example.
This is my first project with Arduino
With a GLCD Screen is not a problem.
But with a TFT is different.
Thanks in advance.
Piet

In line 4 you convert a float (4 byte arduino.cc/en/Reference/Char).
If voltage_string (better variable names?) is larger then 127 your result is wrong.

Tft.drawChar routine is for print a single ASCII char. Not for Numbers.
You must write a routine (if there is no in the tft library) to show float numbers. (arduino.cc/playground/Main/FloatToString)

If you don’t know to handle this please read: google.com

Don’t know if this helps or not, but I wanted to display int values and took this approach. I force the screen to redraw the original text to update what was there (assuming black background). Of course this is for integer values not float.

intTextUpdate(oldx,newx,80,20,2,BLUE);   


void intTextUpdate(int origVal, int newVal, int xpos, int ypos,int fsize, int fcolor){
  String fcColor;
  intTextDisplay(origVal,xpos,ypos,fsize,BLACK);
  intTextDisplay(newVal ,xpos,ypos,fsize,fcolor);
}

void intTextDisplay(int dispval, int xpos, int ypos, int fsize,int fcolor)
{
    char iTocVal[6];
    String(dispval).toCharArray(iTocVal,6);
    Tft.drawString(iTocVal,xpos,ypos,fsize,fcolor);
}