Boost Gauge Oled Display Issue

Hi guys,

I'm a complete newbie when it comes to programing and this is my first project so please bare with me.

I've created a Turbo Boost Gauge and everything seems to be working perfectly on the bench.

The only issue I seem to have is when the Boost gauge shows a negative value i.e -1 PSI the text on the display keeps jumping over (see video attached)

Is there a way I can justify the text to the right so the minus symbol just appears when needed and not throw the text around the screen.

I'm using a 0.96 Oled I2C screen and a Arduino Nano (clone)

I've hunted everywhere and just cant find a solution that I understand.

Any help with be extremely grateful.

v3.ino (1.13 KB)

IMG_8974.mpg (776 KB)

look up the sprintf() function. It will do what you need.

Or, you can just compute the value to display and if it is not negative, print a leading space and then print the number.

float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
int press = (voltage-1.93)*14.9659 + 0.5; // convert to no decimal places with rounding
if ( press >= 0 ) display.print( " ");
display.print(press); display.println("PSI");
display.display();

First calculating voltage and use that to calculate pressure is wasteful... Would be way better to work out the math directly :slight_smile:

And in the process, fixing that haywire 1023 by replacing it with 1024 :wink: