源代碼在附件中,沒有庫的留言。學(xué)習(xí)在實(shí)踐中進(jìn)步,建議大家多發(fā)些源代碼,這樣讓更多人少走彎路,因?yàn)槟愕囊稽c(diǎn)保留說不定會讓世界進(jìn)步的節(jié)奏變的更慢,如果愛迪生沒有告訴大家電燈泡說不定現(xiàn)在我們還點(diǎn)著燈呢。如果沒有人教你說話,現(xiàn)在說不定我們只會比劃。創(chuàng)造要發(fā)動更多的人,你是專家不一定能發(fā)明,或許別人能給你更多思路,或許世界因你而改變,其實(shí)我們每個人的源代碼和創(chuàng)造都來自前人為我們打下的基礎(chǔ)。
制作出來的實(shí)物圖如下:
20181118_120603.jpg (337.39 KB, 下載次數(shù): 134)
下載附件
2018-11-18 12:24 上傳
20181118_120625.jpg (309.1 KB, 下載次數(shù): 123)
下載附件
2018-11-18 12:24 上傳
20181118_120653.jpg (337.52 KB, 下載次數(shù): 138)
下載附件
2018-11-18 12:24 上傳
O128顯DS3231時間源程序如下:
- //A4 A5并用顯示屏和時鐘D3231
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
-
- #define OLED_RESET 4//oled復(fù)位
- Adafruit_SSD1306 display(OLED_RESET);
- #define LOGO16_GLCD_HEIGHT 16 //定義顯示高度
- #define LOGO16_GLCD_WIDTH 16 //定義顯示寬度
- #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();//清除屏幕和緩沖區(qū)
- //1.檢測全屏顯示(看看有沒有大面積壞點(diǎn))
- 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();// 清除屏幕和緩沖區(qū)
- 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);
- }
復(fù)制代碼 |