一款新颖的OLED时钟显示界面

通常的OLED界面都是数字显示的而此款则是几何式的,具体显示效果如下:

所需硬件为OLEDSSD1036,Arduino uno,代码如下已验证有效。


 #include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);  // I2C / TWI 

int hours = 16;
int minutes = 16;
int seconds = 0;
char *number[12]={"6","5","4","3","2","1","12","11","10","9","8","7"};
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
float radius = min(SCREEN_HEIGHT, SCREEN_WIDTH)/2-1;

const int X_CENTER = SCREEN_WIDTH / 2;
const int Y_CENTER = SCREEN_HEIGHT / 2;

int x1, y1, x2, y2;
double angle;

void draw(void) {
  //u8g.drawCircle(X_CENTER, Y_CENTER, radius);
  u8g.drawCircle(X_CENTER, Y_CENTER, 1);
  //draw minute's ticks (60 lines)
  for(int j=1; j<=60; j++){
    angle = j*6;
    angle = angle * 0.0174533;

    x1 = X_CENTER + (sin(angle) * radius);
    y1 = Y_CENTER + (cos(angle) * radius);
    x2 = X_CENTER + (sin(angle) * (radius));
    y2 = Y_CENTER + (cos(angle) * (radius));
    u8g.drawLine(x1,y1,x2,y2);
    
  }
  //draw hour's ticks (12 lines)
  for(int j=0; j<12; j++){
    angle = j*30;
    angle = angle * 0.0174533;

    x1 = X_CENTER + (sin(angle) * radius);
    y1 = Y_CENTER + (cos(angle) * radius);
    x2 = X_CENTER + (sin(angle) * (radius - 4));
    y2 = Y_CENTER + (cos(angle) * (radius - 4));
    u8g.drawLine(x1,y1,x2,y2);
    //draw hour digits(12 lines)
    x2 = X_CENTER + (sin(angle) * (radius - 8));
    y2 = Y_CENTER + (cos(angle) * (radius - 8));
    u8g.setFont(u8g_font_chikita);
    u8g.drawStr(x2-2, y2+3, String(number[j]).c_str());

    angle = seconds*6;
    angle = angle * 0.0174533;
    x2 = X_CENTER + (sin(angle) * (radius - 1));
    y2 = Y_CENTER - (cos(angle) * (radius - 1));
    u8g.drawLine(X_CENTER,Y_CENTER,x2,y2);

    angle = minutes*6;
    angle = angle * 0.0174533;
    x2 = X_CENTER + (sin(angle) * (radius - 10));
    y2 = Y_CENTER - (cos(angle) * (radius - 10));
    u8g.drawLine(X_CENTER,Y_CENTER,x2,y2);

    angle = hours*30 + ((minutes / 12) * 6);
    angle = angle * 0.0174533;
    x2 = X_CENTER + (sin(angle) * (radius / 2));
    y2 = Y_CENTER - (cos(angle) * (radius / 2));
    u8g.drawLine(X_CENTER,Y_CENTER,x2,y2);

    /*
    //draw sweep hand
    float fraction = getCurrentTime() - floor(getCurrentTime());
    angle = (fraction * 360) / 0.0174533;
    x1 = X_CENTER + (sin(angle) * radius - 1);
    y1 = Y_CENTER - (cos(angle) * radius - 1);
    x2 = X_CENTER + (sin(angle) * (radius - 4));
    y2 = Y_CENTER - (cos(angle) * (radius - 4));
    u8g.drawLine(x1,y1,x2,y2);
    */
  }
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();
}

void loop(void) {
  seconds +=1;
  if(seconds==60){ seconds=seconds-60; minutes +=1;}
  if(minutes==60){ minutes=0; hours +=1;}
  if(hours==24){hours=1;}
  //delay(800);
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(500);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值