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);
}
心得:要善于使用已编写好的代码库,事半功倍
实验内容:用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);
}
心得:要善于使用已编写好的代码库,事半功倍
相关文章推荐
- 监测UITextField的变化
- 关于UINavigationController、UINavigationBar 中 navigationItem 左侧 “返回” 按钮的问题
- easyui只显示年月
- git clone的错误fatal: HTTP request failed解决办法
- UIAutomation使用简要介绍
- 设计模式之builder模式
- UI控件之Date & Time组件(上)
- UI细节点滴-UIScorllView和UITableView/UITextView拖动退出键盘方法
- SQL Queries from Transactional Plugin Pipeline
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- easyui的基本用法
- SSIS Passing Parameters to an ADO .NET Source query;向ado.net数据源传递参数。
- Color types not allowed (at ‘drawable’ with value ‘#f0f0f0’)
- UIsheji
- UIsheji
- UiSelector的官方帮助文档
- NGUI自适应
- 实例讲解iOS中的UIPageViewController翻页视图控制器
- iOS UIFont 字体名字大全
- EasyUI在表单提交之前进行验证的实例代码