简体   繁体   English

tinkercad arduino lcd 不显示

[英]tinkercad arduino lcd is not displaying

How I wanted it to work: This is a thing that checks temperature and display the temperature and the temperature that I want.我希望它如何工作:这是一个检查温度并显示温度和我想要的温度的东西。 You can change the hoping temperature by using the buttons.您可以使用按钮更改希望的温度。 One is high and the other is low.If the temperature is higher the fan gets on.If the spaeaker rings just once when the temp is higher than what I wanted it to be.一个是高,另一个是低。如果温度更高,风扇就会启动。如果当温度高于我想要的温度时扬声器只响一次。

There seems to be no error in the code but the lcd is displaying nothing.代码中似乎没有错误,但 lcd 没有显示任何内容。 The speaker, TMP, MOTOR seems to be working well which is strange.扬声器、TMP、MOTOR 似乎运行良好,这很奇怪。 Please help me what's wrong.请帮我看看有什么问题。

Code:代码:

* *

[//LCD_Thermostat
  #include <Wire.h>
  #define TEMP_ADDR 72
  #include <LiquidCrystal.h>
  LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  byte degree\[8\] = {
   B00110,
   B01001,
   B01001,
   B00110,
   B00000,
   B00000,
   B00000,
   B00000,
 };
byte fan_on\[8\] = {
  B00100,
  B10101,
  B01110,
  B11111,
  B01110,
  B10101,
  B00100,
  B00000,
};
 byte fan_off\[8\] = {
  B00100,
  B00100,
  B00100,
  B11111,
  B00100,
  B00100,
  B00100,
  B00000,
};
const int SPEAKER=8;
const int DOWN_BUTTON =9;
const int UP_BUTTON=10;
const int FAN =11;
const int T0=0;
boolean lastDownTempButton    = LOW;
boolean currentDownTempButton = LOW;
boolean lastUpTempButton      = LOW;
boolean currentUpTempButton       = LOW;
int set_temp = 23;          
boolean one_time = false;   
void setup()
{
  pinMode(FAN, OUTPUT);

  //Create a wire object for the temp sensor
  Wire.begin();

  //Set up the LCD's number of columns and rows
  lcd.begin(16, 2);

  //Make custom characters
  lcd.createChar(0, degree);
  lcd.createChar(1, fan_off);
  lcd.createChar(2, fan_on);

  //Print a static message to the LCD
  lcd.setCursor(0,0);
  lcd.print("Current:");
  lcd.setCursor(10,0);
  lcd.write((byte)0);
  lcd.setCursor(11,0);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Set:");
  lcd.setCursor(10,1);
  lcd.write((byte)0);
  lcd.setCursor(11,1);
  lcd.print("C");
  lcd.setCursor(15,1);
  lcd.write(1); 

}
boolean debounce(boolean last, int pin)
{
  boolean current = digitalRead(pin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(pin);
  }
  return current;
}
void loop()
{/*
  Wire.beginTransmission(TEMP_ADDR); 
  Wire.write(0);                         
  Wire.endTransmission();              
  Wire.requestFrom(TEMP_ADDR, 1);   
  while(Wire.available() == 0);          
  int c = Wire.read();  
  */
  // for LM35 temperature sensor (Chapter3. 아날로그 신호와 센서값)
 int c = analogRead(T0);
 c = c*5.0 /1024.0 * 100;
 Serial.println(c);
 lcd.setCursor(8,0); //Move the cursor
 lcd.print(c); //Print this new value
  lcd.setCursor(8,0);                   
  lcd.print(c);                     

  currentDownTempButton = debounce(lastDownTempButton, DOWN_BUTTON);
  currentUpTempButton  = debounce(lastUpTempButton, UP_BUTTON);

  if (lastDownTempButton== LOW && currentDownTempButton == HIGH)
  {
    set_temp--;
  }
  //Turn up the set temp
  else if (lastUpTempButton== LOW && currentUpTempButton  == HIGH)
  {
    set_temp++;
  }
  //Print the set temp
  lcd.setCursor(8,1);
  lcd.print(set_temp);
  lastDownTempButton = currentDownTempButton;
  lastUpTempButton = currentUpTempButton;

  if (c >= set_temp)
  {
    if (!one_time)
    { 
      tone(SPEAKER, 400);
      delay(500);
      one_time = true;
    }
    else
    {
      noTone(SPEAKER);
    }
    digitalWrite(FAN, HIGH);
    lcd.setCursor(15,1);
    lcd.write(2);
  }
  else
  {
    noTone(SPEAKER);
    one_time = false;
    digitalWrite(FAN, LOW);
    lcd.setCursor(15,1);
    lcd.write(1);
  }
}][1]

* *

Try to use LCD wiring as described in LiquidCristal library, use examples such as HelloWorld.尝试使用 LiquidCristal 库中描述的 LCD 接线,使用 HelloWorld 等示例。

Here you can find a 'Hello World' example在这里您可以找到一个“Hello World”示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM