锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

Arduino入门篇:第十章代码及练习答案

时间:2022-08-11 07:00:00 湿度传感器hm1520

编号:simple_LCD1602

[code]
#include
const int rs = 12, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
delay(3000);
}

void loop() {
// put your main code here, to run repeatedly:
for(int a=1; a<=9; a ){
for(int b=1; b<=9; b ){
lcd.setCursor(0,1);
lcd.print(a);
lcd.print('*');
lcd.print(b);
lcd.print('=');
lcd.print(a*b);
delay(1000);
}
lcd.clear();
}
}
[/code]

=========================================================================

编号:tmp_hm_LCD1602

[code]
#include "DHT.h"
#define DHTPIN 7 //DHT11传感器的数据管脚和UNO7号管脚相连
#define DHTTYPE DHT11 ///定义传感器类型DHT11

#include
const int rs = 12, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3; ///定义液晶屏每个管脚

#define ALARM_LED 8 //定义LED8号连接管脚
#define BEEP 9 //定义蜂鸣器的连接管脚为9号

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

float temp, humd; ///定义温度和湿度变量
float htIndex; //热指数

void setup() {
// put your setup code here, to run once:
pinMode(ALARM_LED, OUTPUT);
pinMode(BEEP, OUTPUT);
dht.begin();
lcd.begin(16, 2);
lcd.setCursor(2,0);
lcd.print("TEMPERAUTRE & ");
lcd.setCursor(0,1);
lcd.print("HUMIDITY MONITOR");
delay(3000);
}

void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
lcd.clear();
temp = dht.readTemperature(); ///读取温度值
humd = dht.readHumidity(); ///读取湿度值
lcd.print(" Temperature=");
lcd.print(temp, 1);
lcd.write(0B11011111);
lcd.write(0B01000011); //显示摄氏度符号
lcd.print(" ");
lcd.print("Humidity=");
lcd.print(humd, 1);
lcd.print(%);
for(int i=0; i<24; i ){
lcd.scrollDisplayLeft();
delay(500);
}

lcd.clear();
lcd.setCursor(0,0);
lcd.print("T:");
lcd.print(temp,1);
lcd.write(0B11011111);
lcd.write(0B01000011); //显示摄氏度符号
lcd.print(" ");
lcd.print("H:");
lcd.print(humd, 1);
lcd.print('%');
delay(3000);

htIndex = dht.computeHeatIndex();
if(htIndex <=80){ ///安全范围内
digitalWrite(ALARM_LED, LOW);
digitalWrite(BEEP, LOW);
lcd.setCursor(0,1);
lcd.print("HtIndx=");
lcd.print(htIndex,0);
lcd.print(" :SAFE");
}
else if(htIndex >80 && htIndex <= 101){ ///不适范围内
digitalWrite(ALARM_LED, HIGH);
digitalWrite(BEEP, LOW);
lcd.setCursor(0,1);
lcd.print("HtIndx=");
lcd.print(htIndex,0);
lcd.print(" :WARN");
}
else if(htIndex > 101){ ///危险范围内
digitalWrite(ALARM_LED, HIGH);
digitalWrite(BEEP, HIGH);
lcd.setCursor(0,1);
lcd.print("HtIndx=");
lcd.print(htIndex,0);
lcd.print(":DANGER");
}
delay(3000);
}
[/code]

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章