麻烦帮忙看一下为什么BH1750和DS3231一起用时显示屏就白屏?
#include <UTFT.h>
#include <dht11.h>
#include "SR04.h"
#include <DS3231.h>
#include <Wire.h>
#include <math.h>
int BH1750address = 0x23;
int DS3231address = 0x68;
byte buff[2];
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(QD220A,A2,A1,A5,A4,A3); // Remember to change the model parameter to suit your display module!
float cm;
dht11 DHT11;
int ledpin=(5,6);
#define DHT11PIN 2
const int TrigPin = 3;
const int EchoPin = 4;
int potPin=A6;
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} //摄氏温度度转化为华氏温度
double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度
// 露点(点在此温度时,空气饱和并产生露珠)
// 参考: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// 快速计算露点,速度是5倍dewPoint()
// 参考: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
double BH1750()
{
int i=0;
double val=0;
Wire.beginTransmission(BH1750address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
delay(200);
Wire.beginTransmission(BH1750address);
Wire.requestFrom(BH1750address, 2);
while(Wire.available()) //
{
buff = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
if(2==i)
{
val=((buff[0]<<8)|buff[1])/1.2;
}
return val;
}
void setup()
{
randomSeed(analogRead(0));
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
pinMode(ledpin,OUTPUT);
pinMode(EchoPin,INPUT);
pinMode(TrigPin,OUTPUT);
Wire.begin();
}
void ReadDS3231()
{
int second,minute,hour,date,month,year,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
}
void loop()
{
int buf[218];
int x, x2;
int y, y2;
int r;
int i;
uint16_t val=0;
ReadDS3231();
int chk = DHT11.read(DHT11PIN);
digitalWrite(TrigPin,LOW);
delayMicroseconds(2);
digitalWrite(TrigPin,HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin,LOW);
cm=pulseIn(EchoPin,HIGH)/58.0;
cm=(int(cm*100.0))/100.0;
int n=analogRead(potPin);
float vol=n*0.1399265895812715;
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 255, 0);
myGLCD.print("20", 2, 6);
myGLCD.printNumI(Clock.getYear(), 35, 6);
myGLCD.print("/", 65, 6);
myGLCD.setColor(150, 150, 0);
myGLCD.printNumI(Clock.getMonth(Century), 95, 6);
myGLCD.print("/", 115, 6);
myGLCD.setColor(200, 200, 200);
myGLCD.printNumI(Clock.getDate(), 135, 6);
myGLCD.setColor(VGA_FUCHSIA);
myGLCD.printNumI(Clock.getHour(h12, PM), 30, 33);
myGLCD.print(":", 63, 33);
myGLCD.setColor(VGA_TEAL);
myGLCD.printNumI(Clock.getMinute(), 75, 33);
myGLCD.print(":", 105, 33);
myGLCD.setFont(SevenSegNumFont);
myGLCD.setColor(VGA_YELLOW);
myGLCD.printNumI(Clock.getDoW(), 184, 2);
myGLCD.setFont(SmallFont);
myGLCD.setColor(150, 10, 0);
myGLCD.printNumI(Clock.getSecond(), 121, 37);
myGLCD.setColor(50, 200, 50);
myGLCD.print("Atm", 28, 62);
myGLCD.setColor(200, 50, 200);
myGLCD.print("High", 26, 82);
myGLCD.setColor(200, 100, 20);
myGLCD.print("Illuminance", 2, 102);
myGLCD.printNumI(val, 103, 102);
myGLCD.setColor(200, 200, 200);
myGLCD.print("Lx", 118, 102);
myGLCD.setColor(255, 255, 0);
myGLCD.print("Distance", 12, 122);
myGLCD.setColor(255, 0, 0);
myGLCD.print("cm", 134, 122);
myGLCD.printNumF(cm, 1, 95, 122);
myGLCD.setColor(0, 255, 0);
myGLCD.print("Humidity", 12, 142);
myGLCD.printNumI(DHT11.humidity, 103, 142);
myGLCD.setColor(0, 0, 255);
myGLCD.print("%", 119, 142);
if ( DHT11.humidity<=40)
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("Dry", 172, 142);
}
else if( DHT11.humidity<=60)
{
myGLCD.setColor(200, 200, 0);
myGLCD.print("Comefort", 149, 142);
}
else
{
myGLCD.setColor(0, 0, 200);
myGLCD.print("Moist", 163, 142);
}
myGLCD.setColor(255, 0, 255);
myGLCD.print("Temperature", 2, 162);
myGLCD.setColor(200, 255, 50);
myGLCD.print("oC", 131, 162);
myGLCD.printNumF(vol, 1, 99, 162);
if ( vol<=25)
{
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
myGLCD.setColor(0, 0, 255);
myGLCD.print("Cold", 172, 162);
}
else if( vol<=30)
{
myGLCD.setColor(200, 200, 0);
myGLCD.print("Comfort", 153, 162);
}
else
{
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
myGLCD.setColor(255, 0, 0);
myGLCD.print("Hot", 172, 162);
}
myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 0, 218, 174); //外框
myGLCD.drawLine(90, 52, 90, 172); //传感器名称右侧竖线
myGLCD.drawLine(151, 52, 151, 172); //传感器显示数值右侧竖线
myGLCD.drawLine(180, 2, 180, 52); //星期左侧竖线
myGLCD.drawLine(180, 52, 219, 52); //星期下面横线
myGLCD.drawLine(1, 28, 181, 28); //日期下面横线
myGLCD.drawLine(1, 52, 181, 52); //时间下面横线
myGLCD.drawLine(1, 75, 219, 75); //光照度上面横线
myGLCD.drawLine(1, 95, 219, 95); //光照度上面横线
myGLCD.drawLine(1, 118, 219, 118); //距离上面横线
myGLCD.drawLine(1, 138, 219, 138); //湿度上面横线
myGLCD.drawLine(1, 158, 219, 158); //温度上面横线
delay (500);
}
|