#include <dht11.h>
#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
// OLED
#define OLED_DC 9
#define OLED_CS 10
#define OLED_CLK 12
#define OLED_MOSI 11
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
// DS3231
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
char week[]={
*0*,*S*,*u*,*n*,*M*,*o*,*n*,*T*,*u*,*e*,*W*,*e*,*d*,*T*,*h*,*u*,*F*,*r*,*i*,*S*,*a*,*t*};
//DHT11
dht11 DHT11;
#define DHT11PIN 8 //DHT11 PIN 8 连接UNO 8
void setup() {
Serial.begin(9600);
Wire.begin();
// by default, we*ll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC); // init done
display.display(); // show splashscreen
//delay(2000);
}
void loop() {
ReadDS3231();
delay(1000);
}
void ReadDS3231()
{
display.clearDisplay();
int second,minute,hour,date,month,year,dow,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
dow=Clock.getDoW();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("20");
display.print(year);
display.print("-");
display.print(month);
display.print("-");
display.print(date);
display.print(" ");
display.print(week[Clock.getDoW()*3-2]);
display.print(week[Clock.getDoW()*3-1]);
display.print(week[Clock.getDoW()*3]);
display.println("");
display.println("");
display.setTextSize(3);
SupTime(hour);
display.print(":");
SupTime(minute);
display.setTextSize(2);
display.print(":");
SupTime(second);
display.println("");
display.setTextSize(1);
int chk = DHT11.read(DHT11PIN);
display.print("Humi: ");
display.print((float)DHT11.humidity, 1);
display.print(" %");
display.println("");
display.print("Temp: ");
display.print((float)DHT11.temperature-2, 1);
display.print("`C");
display.display();
}
void SupTime(int time){
if(time<10){
display.print("0");
}
display.print(time);
}
#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
// OLED
#define OLED_DC 9
#define OLED_CS 10
#define OLED_CLK 12
#define OLED_MOSI 11
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
// DS3231
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
char week[]={
*0*,*S*,*u*,*n*,*M*,*o*,*n*,*T*,*u*,*e*,*W*,*e*,*d*,*T*,*h*,*u*,*F*,*r*,*i*,*S*,*a*,*t*};
//DHT11
dht11 DHT11;
#define DHT11PIN 8 //DHT11 PIN 8 连接UNO 8
void setup() {
Serial.begin(9600);
Wire.begin();
// by default, we*ll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC); // init done
display.display(); // show splashscreen
//delay(2000);
}
void loop() {
ReadDS3231();
delay(1000);
}
void ReadDS3231()
{
display.clearDisplay();
int second,minute,hour,date,month,year,dow,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
dow=Clock.getDoW();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("20");
display.print(year);
display.print("-");
display.print(month);
display.print("-");
display.print(date);
display.print(" ");
display.print(week[Clock.getDoW()*3-2]);
display.print(week[Clock.getDoW()*3-1]);
display.print(week[Clock.getDoW()*3]);
display.println("");
display.println("");
display.setTextSize(3);
SupTime(hour);
display.print(":");
SupTime(minute);
display.setTextSize(2);
display.print(":");
SupTime(second);
display.println("");
display.setTextSize(1);
int chk = DHT11.read(DHT11PIN);
display.print("Humi: ");
display.print((float)DHT11.humidity, 1);
display.print(" %");
display.println("");
display.print("Temp: ");
display.print((float)DHT11.temperature-2, 1);
display.print("`C");
display.display();
}
void SupTime(int time){
if(time<10){
display.print("0");
}
display.print(time);
}