学习在实践中进步,建议大家多发些源代码,这样让更多人少走弯路,因为你的一点保留说不定会让世界进步的节奏变的更慢,如果爱迪生没有告诉大家电灯泡说不定现在我们还点着灯呢。如果没有人教你说话,现在说不定我们只会比划。创造要发动更多的人,你是专家不一定能发明,或许别人能给你更多思路,或许世界因你而改变,其实我们每个人的源代码和创造都来自前人为我们打下的基础。
制作出来的实物图如下:
O128显DS3231时间源程序如下:
//A4 A5并用显示屏和时钟D3231#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>#define OLED_RESET 4//oled复位Adafruit_SSD1306 display(OLED_RESET);#define LOGO16_GLCD_HEIGHT 16 //定义显示高度#define LOGO16_GLCD_WIDTH16 //定义显示宽度#include <DS3231.h>DS3231 Clock;bool Century=false;bool h12;bool PM;byte ADay, AHour, AMinute, ASecond, ABits;bool ADy, A12h, Apm;int second,minute,hour,date,month,year,DoW;byte temperature;//温度int y; #if (SSD1306_LCDHEIGHT != 64)#error("Height incorrect, please fix Adafruit_SSD1306.h!");#endif//温(0) 度(1)static const uint8_t PROGMEM wendu_16x16[] ={0x00,0x08,0x00,0x08,0x7C,0x08,0x44,0x08,0x45,0xFE,0x44,0x08,0x44,0x08,0x7C,0x08,0x44,0x88,0x44,0x48,0x44,0x48,0x44,0x08,0x7C,0x08,0x44,0x08,0x00,0x28,0x00,0x10,/*"时",0*/0x20,0x00,0x13,0xFC,0x10,0x04,0x40,0x04,0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,0x47,0xC4,0x40,0x04,0x40,0x14,0x40,0x08,/*"间",1*/};static const uint8_t PROGMEM d_16x16[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"∶",0*/};static const uint8_t PROGMEM g_16x16[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",0*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",0*/};static const uint8_t PROGMEM c_16x16[] ={0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00,/*"℃",0*/};//湿(0) 度(1)ˉ-static const uint8_t PROGMEM shidu_16x16[] ={0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8,0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00,/*"温",0*/0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20,0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E,/*"度",1*/};void setup(){display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// 使用I2C addr 0x3D初始化 (用于128x64)display.clearDisplay();//清除屏幕和缓冲区//1.检测全屏显示(看看有没有大面积坏点)display.fillScreen(WHITE);//显示:填充屏幕(白色)display.display();delay(2000);Wire.begin(); /* //改时间 Clock.setSecond(10);//Set the second Clock.setMinute(40);//Set the minute Clock.setHour(1);//Set the hour Clock.setDoW(7); //Set the day of the week Clock.setDate(24);//Set the date of the month Clock.setMonth(6);//Set the month of the year Clock.setYear(18);//Set the year (Last two digits of the year) */}void ReadDS3231()//读取时间{second=Clock.getSecond(); //时间minute=Clock.getMinute();//时间hour=Clock.getHour(h12, PM);//时间date=Clock.getDate(); //日期 month=Clock.getMonth(Century);//日期year=Clock.getYear();//日期DoW=Clock.getDoW();//星期temperature=Clock.getTemperature();//温度}void loop(){display.clearDisplay();//清除屏幕和缓冲区ReadDS3231();//读取时间display.setTextSize(1);//字号display.setTextColor(WHITE);//y=second*2;//移动画display.setCursor(0,0); //列、、行display.println((int)20/10);//时间display.setCursor( 10,0); //列、、行display.println((int)20%10);//时间display.setCursor( 20,0); //列、、行display.println((int)year/10);//时间display.setCursor( 30,0); //列、、行display.println((int)year%10);//时间display.ShowCN_16( 44,0,g_16x16,sizeof(g_16x16)/32,WHITE); //://列、、行display.setCursor( 62,0);//列、、行display.println((int)month/10);//时间display.setCursor( 74,0);//列、、行display.println((int)month%10);//时间display.ShowCN_16( 84,0,g_16x16,sizeof(g_16x16)/32,WHITE); //://列、、行display.setCursor( 102,0);//列、、行display.println((int)date/10);//时间display.setCursor( 115,0);//列、、行display.println((int)date%10);//时间display.setTextSize(2);//字号display.setTextColor(WHITE);display.setCursor(20,17); //列、、行display.println((int)hour/10);//时间display.setCursor(32,17); //列、、行display.println((int)hour%10);//时间display.ShowCN_16(42,17,d_16x16,sizeof(d_16x16)/32,WHITE); //://列、、行display.setCursor(52,17);//列、、行display.println((int)minute/10);//时间display.setCursor(64,17);//列、、行display.println((int)minute%10);//时间display.ShowCN_16(74,17,d_16x16,sizeof(d_16x16)/32,WHITE); //://列、、行display.setCursor(85,17);//列、、行display.println((int)second/10);//时间display.setCursor(98,17);//列、、行display.println((int)second%10);//时间display.setTextSize(2);//set字号display.setTextColor(WHITE);display.ShowCN_16(20,35,shidu_16x16,sizeof(shidu_16x16)/32,WHITE); //://列、、行display.setCursor(60,35); //列、、行display.println((int)temperature);//温度display.ShowCN_16(90,35,c_16x16,sizeof(c_16x16)/32,WHITE); //://列、、行display.display();delay(10);}