水镜 发表于 2014-3-21 08:20:56

请教高手把OLED显示 换成 IIC的1602显示时钟。


下面是迷你强发的基于OCROBOT Easy的arduino桌面时钟小作品的程序,请教高手把OLED 换成 IIC的1602显示时钟。谢谢。大家可以把手上的1602用上。


//=======调用U8GLIB液晶屏驱动库=====
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
//=======调用DS3231时钟驱动库======
#include <DS3231.h>
#include <Wire.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,temperature;


void setup(void) {


Clock.setClockMode(true);

}

void loop(void) {

//=======读取时钟的各种中值,存入对应变量========

second=Clock.getSecond();            //秒
minute=Clock.getMinute();            //分
hour=Clock.getHour(h12, PM);         //小时 (分上午和下午模式)   
date=Clock.getDate();                   //日
month=Clock.getMonth(Century);          //月
year=Clock.getYear();                      //年(仅2位)
temperature=Clock.getTemperature();         //温度(正负2-3摄氏度误差,温度仅供参考)


//======开始显示==========
u8g.firstPage();                           
do {
    draw();
} while( u8g.nextPage() );


}


//======定义的显示模式======
void draw(void) {
u8g.setPrintPos(0, 45);      //定义显示位置 横向起始位置0 纵向45
if(PM==0)                     //判断变量PM返回值 0就显示AM1就显示PM
{
u8g.print("AM");
}else
{u8g.print("PM");}
u8g.setFont(u8g_font_freedoomr25n); //设定字体(具体请参看 U8GLIB google code页面,大量字体可选)
u8g.print(hour);                  //输出小时的值
u8g.print(":");                        //显示一个冒号
u8g.print(minute,);                //显示分钟的值
u8g.setFont(u8g_font_freedoomr10r);//调整显示字体
u8g.print(":");                         //再显示冒号
u8g.print(second);                     //显示秒

}

mirotalk1943 发表于 2014-4-30 11:54:56

WOW!~OLED displays are great and its cool : )
推薦最優質的 OLED 1602IIC 顯示屏
https://www.youtube.com/watch?v=31n38N0e2TA

http://tw1020178669.fm.alibaba.com/productlist.html
页: [1]
查看完整版本: 请教高手把OLED显示 换成 IIC的1602显示时钟。