液晶屏19264显示显示采集温度的程序
时间: 2023-05-23 21:01:55 浏览: 55
以下是一份可以在液晶屏19264上显示采集温度的程序代码示例:
```
#include <Wire.h> // I2C library
#include <LiquidCrystal_I2C.h> // LiquidCrystal library
LiquidCrystal_I2C lcd(0x27,16,2); // initialize the LCD
void setup()
{
lcd.init(); // initialize the LCD
lcd.backlight(); // turn on the backlight
lcd.clear(); // clear the screen
Serial.begin(9600); // initialize Serial communication
Wire.begin(); // initialize I2C communication
}
void loop()
{
Wire.requestFrom(0x48,2); // request data from temperature sensor
byte msb = Wire.read(); // read the most significant byte
byte lsb = Wire.read(); // read the least significant byte
int temp = (msb << 8) | lsb; // combine the two bytes
temp = temp >> 4; // shift right 4 bits to get actual temperature
float celsius = temp * 0.0625; // convert raw temperature to Celsius
lcd.setCursor(0,0); // set cursor to first column of first row
lcd.print("Temp: "); // print the word "Temp: "
lcd.print(celsius,2); // print the temperature with 2 decimal places
lcd.print(" C"); // print "C" for Celsius
delay(5000); // wait 5 seconds before updating the screen
}
```
这个程序会通过I2C读取一个温度传感器的数据,并显示当前温度值到液晶屏19264上。
请注意,具体的传感器型号和I2C地址可能会因为硬件不同而有所不同,需要根据实际情况进行调整。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)