LCD在模拟环境中不起作用

问题描述

我正在使用 Tinkercad,因为这是我第一次对 LCD 进行编程,所以我只是复制了连接引脚并使其工作的程序。

问题是它只是亮起而没有显示任何内容,我尝试了对 R/W 引脚进行接线和拆线,但这也不起作用,什么也不会显示

我错过了什么?代码其他功能正常。

电路图:

Image of the circuit

这是代码

#include <LiquidCrystal.h>

const int pin = 0; // analog pin
float celsius = 0,farhenheit =0; // temperature variables
float millivolts; //Millivolts from the sensor
int sensor;

const int G_LED = 13;
const int Y_LED = 12;
LiquidCrystal lcd(10,9,5,4,3,2); // Building the LCD


void setup() {
  lcd.begin(16,2);              
  lcd.clear();                  
  lcd.setCursor(0,0);           
  lcd.print("C=");           // "C=","F=" and "mV" should be printed
  lcd.setCursor(0,1);       // on the LCD in a column  
  lcd.print("F=");           
  lcd.setCursor(0,2);            
  lcd.print("mV=");
  
  pinMode(G_LED,OUTPUT);
  pinMode(Y_LED,OUTPUT);

  Serial.begin(9600); 
}

void loop() {
  sensor = analogRead(pin);                    // Reading the value from the LM35 sensor using the A0 ingress
  millivolts = (sensor / 1023.0) * 5000;       // Converting the value in a number that indicates the millivolts
  celsius = ((sensor * 0.00488) - 0.5) / 0.01; // Celsius value (10 mV for each degree,0°=500mV)
  farhenheit = celsius * 1.8 + 32;             // Fahrenheit value
 
  lcd.setCursor(4,2);                         // Set the cursor at the right of "mV="
  lcd.print(millivolts);                       // Print the mV value
  lcd.setCursor(4,0);                         // Same here for °C and °F
  lcd.print(celsius);
  lcd.setCursor(4,1);

  Serial.print(farhenheit);

  if (millivolts < 700) {    // Green LED is on when the temperature is under or equal to 20° 
  // if (celsius < 20) {     // Alternative
    analogWrite(G_LED,255);
    analogWrite(Y_LED,0); }
  else {
    analogWrite(G_LED,0);
    analogWrite(Y_LED,255); // Yellow LED is on when the temperature is above of 20°C
  }  
  delay(1000);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)