找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 11036|回复: 30
打印 上一主题 下一主题
收起左侧

DS3231迷你时钟含温度制作(Arduino源码)0.96寸OLED显示

  [复制链接]
跳转到指定楼层
楼主
源代码在附件中,没有库的留言。学习在实践中进步,建议大家多发些源代码,这样让更多人少走弯路,因为你的一点保留说不定会让世界进步的节奏变的更慢,如果爱迪生没有告诉大家电灯泡说不定现在我们还点着灯呢。如果没有人教你说话,现在说不定我们只会比划。创造要发动更多的人,你是专家不一定能发明,或许别人能给你更多思路,或许世界因你而改变,其实我们每个人的源代码和创造都来自前人为我们打下的基础。

制作出来的实物图如下:


O128显DS3231时间源程序如下:

  1. //A4 A5并用显示屏和时钟D3231
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>

  5. #define OLED_RESET 4//oled复位
  6. Adafruit_SSD1306 display(OLED_RESET);

  7. #define LOGO16_GLCD_HEIGHT 16 //定义显示高度
  8. #define LOGO16_GLCD_WIDTH  16 //定义显示宽度

  9. #include <DS3231.h>
  10. DS3231 Clock;
  11. bool Century=false;
  12. bool h12;
  13. bool PM;
  14. byte ADay, AHour, AMinute, ASecond, ABits;
  15. bool ADy, A12h, Apm;
  16. int second,minute,hour,date,month,year,DoW;
  17. byte   temperature;//温度  
  18. int y;
  19.                              
  20. #if (SSD1306_LCDHEIGHT != 64)
  21. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  22. #endif
  23. //温(0) 度(1)
  24. static const uint8_t PROGMEM wendu_16x16[] ={

  25. 0x00,0x08,0x00,0x08,0x7C,0x08,0x44,0x08,0x45,0xFE,0x44,0x08,0x44,0x08,0x7C,0x08,
  26. 0x44,0x88,0x44,0x48,0x44,0x48,0x44,0x08,0x7C,0x08,0x44,0x08,0x00,0x28,0x00,0x10,/*"时",0*/

  27. 0x20,0x00,0x13,0xFC,0x10,0x04,0x40,0x04,0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,
  28. 0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,0x47,0xC4,0x40,0x04,0x40,0x14,0x40,0x08,/*"间",1*/
  29. };
  30. static const uint8_t PROGMEM d_16x16[] ={
  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"∶",0*/
  33. };
  34. static const uint8_t PROGMEM g_16x16[] ={
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",0*/
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",0*/


  37. };
  38. static const uint8_t PROGMEM c_16x16[] ={
  39. 0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00,
  40. 0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00,/*"℃",0*/
  41. };
  42. //湿(0) 度(1)ˉ-
  43. static const uint8_t PROGMEM shidu_16x16[] ={

  44. 0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8,
  45. 0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00,/*"温",0*/

  46. 0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,
  47. 0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20,
  48. 0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,
  49. 0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E,/*"度",1*/
  50. };

  51. void setup(){

  52. display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// 使用I2C addr 0x3D初始化 (用于128x64)

  53. display.clearDisplay();//清除屏幕和缓冲区
  54.   //1.检测全屏显示(看看有没有大面积坏点)
  55. display.fillScreen(WHITE);//显示:填充屏幕(白色)
  56. display.display();
  57. delay(2000);
  58. Wire.begin();
  59.       /*
  60.          //改时间
  61.         Clock.setSecond(10);//Set the second
  62.         Clock.setMinute(40);//Set the minute
  63.         Clock.setHour(1);  //Set the hour
  64.         Clock.setDoW(7);    //Set the day of the week
  65.         Clock.setDate(24);  //Set the date of the month
  66.         Clock.setMonth(6);  //Set the month of the year
  67.         Clock.setYear(18);  //Set the year (Last two digits of the year)
  68.       */
  69. }
  70. void ReadDS3231()//读取时间
  71. {

  72.   second=Clock.getSecond(); //时间
  73.   minute=Clock.getMinute();//时间
  74.   hour=Clock.getHour(h12, PM);//时间
  75.   date=Clock.getDate(); //日期   
  76.   month=Clock.getMonth(Century);//日期
  77.   year=Clock.getYear();  //日期  
  78.   DoW=Clock.getDoW();//星期

  79.   temperature=Clock.getTemperature();//温度
  80. }
  81. void loop(){
  82.   
  83. display.clearDisplay();//  清除屏幕和缓冲区
  84. ReadDS3231();//读取时间

  85. display.setTextSize(1);//字号
  86. display.setTextColor(WHITE);
  87. //y=second*2;//移动画
  88. display.setCursor(0,0); //列、、行
  89. display.println((int)20/10);//时间
  90. display.setCursor( 10,0); //列、、行
  91. display.println((int)20%10);//时间
  92. display.setCursor( 20,0); //列、、行
  93. display.println((int)year/10);//时间
  94. display.setCursor( 30,0); //列、、行
  95. display.println((int)year%10);//时间

  96. display.ShowCN_16( 44,0,g_16x16,sizeof(g_16x16)/32,WHITE); //://列、、行

  97. display.setCursor( 62,0);//列、、行
  98. display.println((int)month/10);//时间
  99. display.setCursor( 74,0);//列、、行
  100. display.println((int)month%10);//时间
  101. display.ShowCN_16( 84,0,g_16x16,sizeof(g_16x16)/32,WHITE); //://列、、行

  102. display.setCursor( 102,0);//列、、行
  103. display.println((int)date/10);//时间
  104. display.setCursor( 115,0);//列、、行
  105. display.println((int)date%10);//时间

  106. display.setTextSize(2);//字号
  107. display.setTextColor(WHITE);

  108. display.setCursor(20,17); //列、、行
  109. display.println((int)hour/10);//时间
  110. display.setCursor(32,17); //列、、行
  111. display.println((int)hour%10);//时间

  112. display.ShowCN_16(42,17,d_16x16,sizeof(d_16x16)/32,WHITE); //://列、、行

  113. display.setCursor(52,17);//列、、行
  114. display.println((int)minute/10);//时间
  115. display.setCursor(64,17);//列、、行
  116. display.println((int)minute%10);//时间
  117. display.ShowCN_16(74,17,d_16x16,sizeof(d_16x16)/32,WHITE); //://列、、行

  118. display.setCursor(85,17);//列、、行
  119. display.println((int)second/10);//时间
  120. display.setCursor(98,17);//列、、行
  121. display.println((int)second%10);//时间

  122. display.setTextSize(2);//set字号
  123. display.setTextColor(WHITE);
  124. display.ShowCN_16(20,35,shidu_16x16,sizeof(shidu_16x16)/32,WHITE); //://列、、行
  125. display.setCursor(60,35); //列、、行
  126. display.println((int)temperature);//温度
  127. display.ShowCN_16(90,35,c_16x16,sizeof(c_16x16)/32,WHITE); //://列、、行
  128. display.display();

  129. delay(10);
  130. }
复制代码

评分

参与人数 1黑币 +100 收起 理由
admin + 100 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏6 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:292518 发表于 2019-1-25 15:32 | 只看该作者
居然有传说 中的沙发?????太难了,学不来。。。。
回复

使用道具 举报

板凳
ID:481306 发表于 2019-2-28 07:27 | 只看该作者
非常不错,感谢分享。
回复

使用道具 举报

地板
ID:60624 发表于 2019-2-28 20:09 | 只看该作者
非常不错,感谢分享。
回复

使用道具 举报

5#
ID:495626 发表于 2019-3-21 22:15 | 只看该作者
卧室想搞个时间温湿度的,感谢楼主了!
回复

使用道具 举报

6#
ID:479945 发表于 2019-4-10 12:44 | 只看该作者
非常不错,感谢分享。
回复

使用道具 举报

7#
ID:209380 发表于 2019-4-15 07:17 | 只看该作者
硬件齐了,软件不会。学习任重道远
回复

使用道具 举报

8#
ID:506172 发表于 2019-4-19 13:08 | 只看该作者
有库吗
回复

使用道具 举报

9#
ID:414937 发表于 2019-5-9 23:23 | 只看该作者
非常不错,感谢分享。
回复

使用道具 举报

10#
ID:471632 发表于 2019-5-10 21:50 | 只看该作者
程序能再给点详细说明就好了。
回复

使用道具 举报

11#
ID:583873 发表于 2019-9-19 07:16 | 只看该作者
能把库文件一起打包就更好了
回复

使用道具 举报

12#
ID:660586 发表于 2019-12-13 17:03 | 只看该作者
找到了,下载研究下。
回复

使用道具 举报

13#
ID:660586 发表于 2019-12-13 17:04 | 只看该作者
正在研究DS1302应该差不多一样。。DS3231迷你时钟含温度制作(Arduino源码)0.96寸OLED显示
回复

使用道具 举报

14#
ID:471632 发表于 2020-1-8 20:40 | 只看该作者
这个说一下编程思路或者弄个流程图。手里硬件差不多了,动手试试看
回复

使用道具 举报

15#
ID:234938 发表于 2020-1-14 22:46 | 只看该作者
DS3231只能提前预设时间吗,可否与电脑连接后,直接获取电脑时间?感谢楼主分享。
回复

使用道具 举报

16#
ID:471632 发表于 2020-1-23 15:41 | 只看该作者
设计原理,设计思路都详细说一下,对大家不是更好些吗?
回复

使用道具 举报

17#
ID:162514 发表于 2020-1-28 12:58 | 只看该作者
很好啊!
回复

使用道具 举报

18#
ID:582494 发表于 2020-3-8 21:24 | 只看该作者
收藏学习
回复

使用道具 举报

19#
ID:171746 发表于 2020-3-16 07:53 | 只看该作者
Arduino:1.8.12 (Windows 7), 开发板:"Arduino Uno"

sketch_jul06a:25:2: error: #error ("Height incorrect, please fix Adafruit_SSD1306.h!");

"Adafruit_SSD1306.h" 对应多个库
已使用: C:\Users\Administrator\sketchbook\libraries\Adafruit_SSD1306
未使用:C:\Users\Administrator\sketchbook\libraries\Adafruit_SSD1306_Wemos_Mini_OLED
exit status 1
#error ("Height incorrect, please fix Adafruit_SSD1306.h!");

在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。
没通过啊?  
回复

使用道具 举报

20#
ID:110875 发表于 2020-10-7 22:17 | 只看该作者
支持楼主的观点,希望楼主提供一下ShowCN_16(90,35,c_16x16,sizeof(c_16x16)/32,WHITE); 的库文件,我最近也开始接触Arduino板子了,想走点近路
回复

使用道具 举报

21#
ID:233561 发表于 2020-10-16 22:01 | 只看该作者
怎么接线的啊楼主
回复

使用道具 举报

22#
ID:449574 发表于 2020-11-16 20:36 | 只看该作者
编译ShowCN_16(90,35,c_16x16,sizeof(c_16x16)/32,WHITE);的库文件
回复

使用道具 举报

23#
ID:28992 发表于 2021-3-24 07:36 | 只看该作者
thank u for sharing!
回复

使用道具 举报

24#
ID:430492 发表于 2021-4-29 12:24 | 只看该作者
感谢楼主分享,如果有再详细点的说明就更好了,谢谢!!
回复

使用道具 举报

25#
ID:374259 发表于 2021-6-5 23:29 | 只看该作者
如果有再详细点的说明就更好了
回复

使用道具 举报

26#
ID:884042 发表于 2021-7-30 16:05 | 只看该作者
楼主这个是几乘几的屏幕啊?看起来好大,是128乘128的吗?
回复

使用道具 举报

27#
ID:957684 发表于 2021-7-30 16:16 | 只看该作者
尽量学习了!刚接触单片机!
回复

使用道具 举报

28#
ID:964490 发表于 2021-9-7 00:08 | 只看该作者
DS1302的代码楼主有研究过吗?
回复

使用道具 举报

29#
ID:160658 发表于 2021-10-23 16:12 | 只看该作者
编译通过不了,报错:DS3231_oled_spi:24:2: error: #error ("Height incorrect, please fix Adafruit_SSD1306.h!");
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
  ^~~~~
exit status 1
#error ("Height incorrect, please fix Adafruit_SSD1306.h!");
回复

使用道具 举报

30#
ID:972563 发表于 2021-11-19 11:16 | 只看该作者
ds3231的温度测试你觉得准吗?和ds18b20差的可是够大的
回复

使用道具 举报

31#
ID:1001427 发表于 2022-4-16 20:47 来自手机 | 只看该作者
有库吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表