本帖最后由 a6641 于 2016-5-19 11:34 编辑
#include <U8glib.h>
#include <RTClib.h>
#include "DHT.h"
#include <Wire.h>
#include <Adafruit_BMP085.h>
#define DHTPIN 8 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
RTC_DS1307 RTC;
void draw(void) {
u8g.setFont(u8g_font_unifont);
// put your main code here, to run repeatedly:233lollollol
u8g.drawStr(0,22,"Pa:");
u8g.drawStr(bmp.readPressure());
u8g.drawStr("/");
u8g.drawStr("temp:");
u8g.drawStr(t);
u8g.drawStr(now.year(), DEC);
u8g.drawStr('/');
u8g.drawStr(now.month(), DEC);
u8g.drawStr('/');
u8g.drawStr(now.day(), DEC);
u8g.drawStr(' ');
u8g.drawStr(now.hour(), DEC);
u8g.drawStr(':');
u8g.drawStr(now.minute(), DEC);
u8g.drawStr(':');
u8g.drawStr(now.second(), DEC);
}
void setup(void) {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
bmp.begin();
Wire.begin();
RTC.begin(); // initialize the lcd
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
// Print a message to the LCD.
}
void loop(void){
DateTime now = RTC.now();
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
// pressure of 1013.25 millibar = 101325 Pascal
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude());
Serial.println(" meters");
}
是将温度,湿度,大气压在12864显示屏上显示的
|