小学期第二天
实验内容:用LCD显示屏显示当前温度,一秒钟刷新两次
实验器材:跳线、LCD显示屏、温度传感器、可调电阻、面包板、数据线、220欧姆电阻
电路图:
代码:
// include the library code:
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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);
}
// 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); //使用浮点数存储温度数据ÿ
float dat;
int n = analogRead(A0); //读取A0口的电压值
dat = n*(5.0/1023.0*100); //使用浮点数存储温度数据ÿ