您的位置:首页 > 产品设计 > UI/UE

Arduino LCD 温度显示

2016-06-24 11:10 387 查看
小学期第二天

实验内容:用LCD显示屏显示当前温度,一秒钟刷新两次

实验器材:跳线、LCD显示屏、温度传感器、可调电阻、面包板、数据线、220欧姆电阻

电路图:

代码:

 // include the library code:

 #include <LiquidCrystal.h>

 // initialize the library with the numbers of the interface pins

 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 void setup() {

   // set up the LCD's number of columns and rows:

   lcd.begin(16, 2);

   // Print a message to the LCD.

   lcd.print("The temperature");

   lcd.setCursor(0, 1);

   lcd.print("is: ");

   Serial.begin(9600); 

 }

 void loop() {

   float dat;

   int n = analogRead(A0);    //读取A0口的电压值

   dat = n*(5.0/1023.0*100);   //使用浮点数存储温度数据,温度数据由电压值换算得到

   Serial.print("Tep:");

   Serial.print(dat);                   //串口输出温度数据

   Serial.println("C");

 

   // set the cursor to column 0, line 1

   // (note: line 1 is the second row, since counting begins with 0):

   lcd.setCursor(4, 1);

   // print the number of seconds since reset:

   lcd.print(dat);

   lcd.setCursor(9, 1);

   lcd.print("C");

   delay(500);   

 }

心得:要善于使用已编写好的代码库,事半功倍
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: