interger values not being over written on UTFT?

Hi!,

I’m having a strange problem with utft on a 4.3" display and sainsmart Due, I believe this is software not hardware so I haven’t gone into to much detail of the hardware used.

The code I’m using is a simple analogRead from a potentiometer which shows the integer value of 0v to 5v to figure out the aesthetics of the display.

The problem is everytime a value goes one digit larger i.e “9” to “10” it doesn’t overwrite the second digit when going from two digits back to one digit so for example - as its to be used as a speedometer - it would go “9…10…11…12 then 12…11…10…90…80…70” if that makes sense? another example would be it going over 100 then back to 0 “100, 990, 980, 970, 960…110,100, 900, 800” So it looks like it goes from 10mph to 90mph rather than 09mph.

I’m using the myGLCD.printNumI function but I have tried with the myGLCD.printNumF which is for floating point which worked better but obvious due to larger resolution left lots of decimal points which I suppose could be useful but I doubt I’m going to care about 0.1mph difference on a motorbike going 70mph aha

I have searched for a while but I can’t see how other people have done it, From what I understand you need to remove the previous value before posting a new one, but the clear screen function obviously makes the screen and text flash, I have also tried making a box behind the text so it doesn’t need to refresh the whole screen just what is needed. I had an idea that if I used an image for the whole background created on photoshop rather than drawing lines and box’s all over the place I could focus on the refresh rate of the print functions but I really dont know what I’m talking about so…

If it will help here is the code;

#include <UTFT.h>



extern uint8_t SmallFont[];
extern uint8_t BigFont[];

UTFT myGLCD(ITDB43,38,39,40,41);


void setup()
{
  myGLCD.InitLCD();
  Serial.begin(9600);
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_BLACK);
  Serial.println(finalNum);
}

void loop()
{
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(1);

  myGLCD.setBackColor(0,0,0);
  myGLCD.setFont(BigFont);
  myGLCD.setColor(255,255,255);
  myGLCD.printNumF(sensorValue, 1, 200, 80);


}

Go on. You have been here for a few weeks.

You either right-justify all your numbers so that they line up or you print a trailing space to "rub out" any surplus digits that are left over from the previous number.

Or you rub out the whole number with fillRect() before you write the new value.

There are many ways to skin a cat.

David.

david_prentice: Go on. You have been here for a few weeks.

You either right-justify all your numbers so that they line up or you print a trailing space to "rub out" any surplus digits that are left over from the previous number.

Or you rub out the whole number with fillRect() before you write the new value.

There are many ways to skin a cat.

David.

Thanks David!,

How would you right-justify on UTFT?

What would you recommend is the most efficient way?

Well, you can use itoa(), ltoa(), ftoa() or dstrtof() to produce the human readable ascii string. Then calculate padding with strlen(),

Or you can use the bloated and inefficient String methods.

Having produced the appropriate justified string, you print it with UTFT.

Whereas the Stream methods used by Serial, LiquidCrystal, ... are pretty horrible for formatting, UTFT requires you to set the cursor for every print.

Life is so much simpler with C and printf(). You can of course use sprintf() to right justify your expression.

David.

david_prentice:
Well, you can use itoa(), ltoa(), ftoa() or dstrtof() to produce the human readable ascii string. Then calculate padding with strlen(),

Or you can use the bloated and inefficient String methods.

Having produced the appropriate justified string, you print it with UTFT.

Whereas the Stream methods used by Serial, LiquidCrystal, … are pretty horrible for formatting, UTFT requires you to set the cursor for every print.

Life is so much simpler with C and printf(). You can of course use sprintf() to right justify your expression.

David.

Thanks for your help!

I look into dstrtof() a little bit before I posted and I think doing it that way for multiple inputs would be a challenge for me and my little knowledge of arduino and programming! I ended up just adding a fillRect() everytime it changed value, I’m not 100% I done it right but it seems to work now! (he says…)

code;

#include <UTFT.h>



extern uint8_t SmallFont[];
extern uint8_t BigFont[];

UTFT myGLCD(ITDB43,38,39,40,41);
int sensorValue;
int sensorLastState = 0;


void setup()
{
  myGLCD.InitLCD();
  Serial.begin(9600);
  myGLCD.clrScr();
  myGLCD.fillScr(VGA_BLACK);
}

void loop()
{
  sensorValue = analogRead(A0); // read sensor
  sensorLastState == sensorValue;
  
  myGLCD.setBackColor(0,0,0);
  myGLCD.setFont(BigFont);
  myGLCD.setColor(255,255,255);
  myGLCD.printNumI(sensorValue, 200, 80);
  delay(50);
  Serial.print(sensorValue);
  Serial.print(sensorLastState);

  
  if (sensorValue != sensorLastState)
  {
    myGLCD.setColor(0,0,0);
    myGLCD.fillRect(200, 80, 275, 100); 
  }


}