2

I'm developing system that will showing output on LCD.

I declare variable data type as float, but the LCD display showing 0.00 that I don't initialize, because I declare it with 0.0

I want the LCD display showing 0.000, but whatever I try to change the initialize value the LCD Display always showing 0.00 .So, how I can make the LCD Display showing 0.000

This is the link for the image
Below are my code:

#include <LiquidCrystal.h>

volatile int NbTopsFan;
float flowrate = 0.0;
float volume = 0.0;
int hallSensor = 2;


LiquidCrystal lcd (12, 11, 9, 8, 7, 6);
void rpm() {
  NbTopsFan++;
}

void setup(){
  pinMode(3, OUTPUT);
  pinMode (hallSensor, INPUT);
  Serial.begin (9600);
  attachInterrupt (0, rpm, RISING);

  lcd.begin (16, 2);
  lcd.clear ();
}
void loop (){
  digitalWrite(3, HIGH);
  NbTopsFan=0;
  sei();
  delay(1000);
  cli();
  flowrate = NbTopsFan / 7.5;
  volume += (flowrate / 60);



  lcd.clear ();
  lcd.setCursor(0, 0);
  lcd.print("flow :");
  lcd.print(flowrate);
  lcd.print("L/m");
  lcd.setCursor(0, 1);
  lcd.print("VOl :");
  lcd.print(volume);
  lcd.print("L");

  Serial.print("Pulse");
  Serial.print(NbTopsFan);
  Serial.print(flowrate);
  Serial.print("L/m");
  Serial.print(volume,4);
  Serial.print("liter");
}
Uchanet
  • 21
  • 1
  • 1
  • 5

1 Answers1

5

According to the documentation of Print, to specify the number of decimal places to be used, a second parameter is needed. So in you example you could use

lcd.print(flowrate,4);

and

 lcd.print(volume,4);
Demetris
  • 2,981
  • 2
  • 25
  • 33
  • ok, thank you for the answer, but when I try to use Sertial.println(volume,4); why cann't show same case?..
    what should I do...
    – Uchanet Oct 16 '14 at 14:05