gpt4 book ai didi

floating-point - LCD显示不同 float

转载 作者:行者123 更新时间:2023-12-01 21:15:36 26 4
gpt4 key购买 nike

我正在开发将在 LCD 上显示输出的系统。

我将变量数据类型声明为 float,但 LCD 显示屏显示 0.00 我没有初始化,因为我用 0.0

声明它我希望 LCD 显示屏显示 0.000,但无论我尝试更改初始化值,LCD 显示屏始终显示 0.00.那么,我怎样才能让液晶显示屏显示0.000

This is the link for the image
以下是我的代码:

#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");
}

最佳答案

根据Print的文档,要指定要使用的小数位数,需要第二个参数。所以在你的例子中你可以使用

lcd.print(flowrate,4);

 lcd.print(volume,4);

关于floating-point - LCD显示不同 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25439146/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com