本帖最后由 付翔鹰 于 2018-6-1 21:19 编辑
本产品使用 Arduino Leonardo 的单片机,外置2004A四行显示屏,SR04超声波模块,以及开关模块,温湿度模块等先进模块
具体代码:
#include <SoftI2CMaster.h>
#include <LiquidCrystal_SoftI2C.h>
#include <dht.h>
volatile float my_1;
volatile float my_2;
volatile float my_3;
volatile float my_4;
volatile float my_5;
volatile float my_6;
volatile float my_7;
volatile float my_8;
LiquidCrystal_SoftI2C mylcd(0x3f,20,4,A1,A2);
dht myDHT_10;
int dht_10_gettemperature() {
int chk = myDHT_10.read11(10);
int value = myDHT_10.temperature;
return value;
}
int dht_10_gethumidity() {
int chk = myDHT_10.read11(10);
int value = myDHT_10.humidity;
return value;
}
float checkdistance_11_12() {
digitalWrite(11, LOW);
delayMicroseconds(2);
digitalWrite(11, HIGH);
delayMicroseconds(10);
digitalWrite(11, LOW);
float distance = pulseIn(12, HIGH) / 58.00;
delay(10);
return distance;
}
void setup()
{
mylcd.init();
mylcd.backlight();
my_1 = 0;
my_2 = 0;
my_3 = 0;
my_4 = 0;
my_5 = 0;
pinMode(11, OUTPUT);
pinMode(12, INPUT);
my_6 = 0;
my_7 = 0;
my_8 = 0;
}
void loop()
{
mylcd.setCursor(1-1, 1-1);
mylcd.print("....................");
mylcd.setCursor(1-1, 2-1);
mylcd.print("......edition:......");
mylcd.setCursor(1-1, 3-1);
mylcd.print(".......1.0.1........");
mylcd.setCursor(1-1, 4-1);
mylcd.print("....................");
delay(1000);
mylcd.clear();
mylcd.setCursor(1-1, 1-1);
mylcd.print("welcome to use the ");
mylcd.setCursor(1-1, 2-1);
mylcd.print("meteorologic ");
mylcd.setCursor(1-1, 3-1);
mylcd.print("instument named");
mylcd.setCursor(1-1, 4-1);
mylcd.print("FXCS102as");
delay(3000);
mylcd.setCursor(1-1, 1-1);
mylcd.print(" I am FuXiangying");
mylcd.setCursor(1-1, 2-1);
mylcd.print(" I set up the ");
mylcd.setCursor(1-1, 3-1);
mylcd.print(" company named FX ");
mylcd.setCursor(1-1, 4-1);
mylcd.print(" in 7,7,2017");
delay(3000);
mylcd.clear();
my_1 = dht_10_gettemperature();
my_2 = dht_10_gethumidity();
my_3 = my_1 * 1.8;
my_4 = my_3 + 32;
my_5 = checkdistance_11_12();
mylcd.setCursor(1-1, 1-1);
mylcd.print(String(my_1) + String("degree Celsius"));
mylcd.setCursor(1-1, 2-1);
mylcd.print(String(my_4) + String("Fahrenheit"));
mylcd.setCursor(1-1, 3-1);
|