Arduino oled display decimal

Hi guys, i ran into some problems with the oled display.
I was trying to make a boost controller for a car with a potentionmeter,
I set the potentionmeter value as max on the display
the map sensor value from the car is correct it's displaying me 0.00
i tried everything to make the "max" value to shown as 0.00 too but with any success

Here is the code:

#include <SPI.h>
#include <Wire.h>
#include <max6675.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define potentiometer A3
#define relay 7
#define alarmr 9
int pottemperature;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
int rawValue; // A/D readings
int offset = 102; // zero pressure adjust
int fullScale = 922; // max pressure (span) adjust
float pressure; // final pressure




#define OLED_RESET     -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


void setup() {
  Serial.begin(9600);
  Wire.begin();   
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  pinMode(potentiometer, INPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, LOW);
  pinMode(alarmr, OUTPUT);
  digitalWrite(alarmr, LOW);
  display.setTextSize(2);
  display.setTextColor(WHITE);

  updatedisplay();
 }

void loop() {
  rawValue = analogRead(A0);
   pressure = (rawValue - offset) * 3.0 / (fullScale - offset); // conversion
  updatedisplay();
  delay(300);
    if (pressure < pottemperature) {
      digitalWrite(relay, HIGH);
    }
    else if (pressure > pottemperature) {
      digitalWrite(relay , LOW);
      delay(0);
    }
    if (pressure < 1.4 ) {
      digitalWrite(alarmr , HIGH);
    }
    else if (12 > 27) {
     digitalWrite(alarmr , LOW);
    }
  }

 
void zero() {

  }

void updatedisplay() {
  pottemperature = analogRead(potentiometer);
  pottemperature = map(pottemperature, 1, 1023, 0, 1.41);
  display.clearDisplay();
  display.setCursor(15, 20);
  display.print("MAX:");
  display.print(pottemperature, 1);
  display.setCursor(15, 40);
  display.print("BAR:");
  display.print(pressure);
  display.setCursor(5, 0);
  display.print("Levi TURBO");
  display.display();
}

Thanks for any help to make this work, the solenoid control is not done yet, i stopped beacuse of this. The max value what can be set would be 1.40 Bar

What is your problem exactly?
The value do not showed in the display at all or it displayed incorrectly or anything else?

This code displays the MAX value from the potentionmeter.
I want to display as 0.00
so that i can set it max to 1.40

If the problem is that you want to view 2 digits after the point, try this

only showing 1 digit, it's doesn't want to put point there, i even tried to put the max value to 1.41 here, but it's only showing max by setting with potentionmeter

pottemperature = map(pottemperature, 1, 1023, 0, 1.41);

The map() function can only be used to map integer values, not floats

Problem 1: 'pottemperature' is an 'int'. It has no decimal places. To fix it, change to:
float pottemperature;

Problem 2: The 'map()' function only does integers. To fix it, change to:

  pottemperature = analogRead(potentiometer);
  pottemperature = (pottemperature * 1.41) / 1024.0; 

Problem 3: You can't specify the number of decimal places to display on an 'int' because it doesn't have any. Fixing Problem 1 will get you 1 decimal place. To get 2, change to:

  display.print("MAX:");
  display.print(pottemperature, 2);

or

  display.print("MAX:");
  display.print(pottemperature);  // 2 places is the defult

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.