8401| 4
|
[求助] 关于1602显示器 显示问题 求帮助 |
凌风清羽 发表于 2016-3-30 17:36 #include <dht11.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x20,16,2); //设置LCD的地址为0x20,可以设置2行,每行16个字符 dht11 DHT; #define DHT11_PIN 4 #define ECHOPIN 2 #define TRIGPIN 3 void setup(){ lcd.init(); // LCD初始化设置 lcd.backlight(); // 打开LCD背光 Serial.begin(9600); // 设置串口波特率9600 pinMode(ECHOPIN, INPUT); pinMode(TRIGPIN, OUTPUT); Serial.println("Hum(%),\tTem(C),\tDis,\tLig"); lcd.print("H: "); //LCD屏显示” Humidity(%):” lcd.print("T: "); //LCD屏显示”Temp(C):” lcd.print("D: "); lcd.print("L: "); } void loop(){ int chk; //chk用于存储DHT11传感器的数据 chk = DHT.read(DHT11_PIN); int val; val=analogRead(0); digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS delayMicroseconds(2); digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging delayMicroseconds(10); digitalWrite(TRIGPIN, LOW); // Send pin low again int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse distance= distance/58; // Calculate distance from time of pulse int val1; val1=analogRead(3);//Read Gas value from analog 0 //串口显示温湿度值 Serial.print(DHT.humidity,1); Serial.print(",\t"); Serial.print(DHT.temperature,1); Serial.print(",\t "); Serial.print(distance,DEC); Serial.print(",\t "); Serial.println(val1,DEC); //LCD显示温湿度值 lcd.setCursor(0, 1); lcd.print(DHT.humidity,1); lcd.setCursor(4, 1); lcd.print(DHT.temperature,1); lcd.setCursor(8, 1); lcd.print(distance,DEC); lcd.setCursor(12, 1); lcd.print(val1,DEC); delay(1000); } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed