Hardware components | ||||||
| × | 1 |
I found a code in the www to display the time on an OLED 128x64 display, using the DS3231 clock module. However the numbers were pretty tiny, so I created the bigger numbers myself. Maybe not coded the most elegant way, but at least it worked.
To get the code for the numbers, I first typed it in Microsoft Paint, saved the bmp in momocrome number after number, and then converted into code using the LCD_Bitmap_Converter.
int Stunde_1;
int Stunde_2;
int Stunde_1_tmp = -1;
int Stunde_2_tmp = -1;
int Stunde_String;
int Minute_1;
int Minute_2;
int Minute_1_tmp = -1;
int Minute_2_tmp = -1;
int Minute_String;
int DST = 0;
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
RTC_DS3231 rtc;
const uint8_t bitmap_Doppelpunkt[] PROGMEM = {
254, 254, 254, 254, 254, 254, 254, 0, 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254
};
const uint8_t bitmap_0[] PROGMEM = {
0, 255, 0, 3, 255, 192, 7, 255, 224, 15, 255, 240, 31, 255, 248, 31, 255, 248, 63, 195, 252, 63, 129, 252, 127, 0, 254, 127, 0, 254, 127, 0, 254, 126, 0, 126, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 126, 0, 126, 127, 0, 254, 127, 0, 254, 127, 0, 254, 63, 129, 252, 63, 195, 252, 63, 255, 248, 31, 255, 248, 15, 255, 240, 7, 255, 224, 3, 255, 192, 0, 127, 0
}; //3
const uint8_t bitmap_1[] PROGMEM = {
0, 7, 224, 0, 7, 224, 0, 15, 224, 0, 15, 224, 0, 31, 224, 0, 63, 224, 0, 127, 224, 1, 255, 224, 3, 255, 224, 15, 255, 224, 31, 255, 224, 31, 239, 224, 31, 207, 224, 31, 143, 224, 30, 15, 224, 16, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224
}; //3
const uint8_t bitmap_2[] PROGMEM = {
0, 127, 128, 3, 255, 224, 7, 255, 240, 15, 255, 248, 31, 255, 252, 31, 255, 254, 63, 193, 254, 63, 128, 255, 127, 128, 127, 127, 0, 127, 127, 0, 127, 31, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 254, 0, 0, 254, 0, 1, 254, 0, 3, 252, 0, 7, 252, 0, 15, 248, 0, 31, 240, 0, 63, 224, 0, 127, 192, 0, 255, 128, 1, 255, 0, 3, 254, 0, 7, 252, 0, 7, 248, 0, 15, 240, 0, 31, 240, 0, 63, 224, 0, 63, 255, 255, 127, 255, 255, 127, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
}; //3
const uint8_t bitmap_3[] PROGMEM = {
0, 254, 0, 3, 255, 128, 7, 255, 224, 15, 255, 240, 31, 255, 240, 63, 255, 248, 63, 199, 248, 63, 131, 252, 127, 129, 252, 127, 1, 252, 7, 1, 252, 0, 1, 252, 0, 1, 252, 0, 3, 248, 0, 7, 248, 0, 31, 240, 0, 63, 224, 0, 63, 128, 0, 63, 224, 0, 63, 240, 0, 63, 252, 0, 1, 252, 0, 0, 254, 0, 0, 255, 0, 0, 127, 0, 0, 127, 30, 0, 127, 254, 0, 127, 255, 0, 127, 255, 0, 255, 127, 128, 254, 127, 195, 254, 63, 255, 252, 63, 255, 252, 31, 255, 248, 15, 255, 240, 3, 255, 192, 0, 255, 0
}; //3
const uint8_t bitmap_4[] PROGMEM = {
0, 0, 252, 0, 0, 1, 252, 0, 0, 3, 252, 0, 0, 3, 252, 0, 0, 7, 252, 0, 0, 15, 252, 0, 0, 15, 252, 0, 0, 31, 252, 0, 0, 63, 252, 0, 0, 63, 252, 0, 0, 127, 252, 0, 0, 255, 252, 0, 0, 255, 252, 0, 1, 253, 252, 0, 3, 249, 252, 0, 3, 249, 252, 0, 7, 241, 252, 0, 15, 225, 252, 0, 15, 225, 252, 0, 31, 193, 252, 0, 63, 129, 252, 0, 63, 129, 252, 0, 127, 1, 252, 0, 254, 1, 252, 0, 255, 255, 255, 224, 255, 255, 255, 224, 255, 255, 255, 224, 255, 255, 255, 224, 255, 255, 255, 224, 255, 255, 255, 224, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0, 0, 1, 252, 0
}; //4
const uint8_t bitmap_5[] PROGMEM = {
7, 255, 254, 0, 7, 255, 254, 0, 7, 255, 254, 0, 15, 255, 254, 0, 15, 255, 254, 0, 15, 255, 254, 0, 15, 255, 254, 0, 15, 224, 0, 0, 31, 192, 0, 0, 31, 192, 0, 0, 31, 192, 0, 0, 31, 192, 0, 0, 31, 223, 128, 0, 63, 255, 224, 0, 63, 255, 248, 0, 63, 255, 252, 0, 63, 255, 254, 0, 63, 255, 254, 0, 127, 193, 255, 0, 127, 128, 255, 0, 15, 0, 127, 0, 0, 0, 63, 128, 0, 0, 63, 128, 0, 0, 63, 128, 0, 0, 63, 128, 0, 0, 63, 128, 30, 0, 63, 128, 254, 0, 63, 128, 255, 0, 127, 128, 127, 0, 127, 0, 127, 128, 255, 0, 127, 193, 254, 0, 63, 255, 254, 0, 31, 255, 252, 0, 31, 255, 248, 0, 7, 255, 240, 0, 3, 255, 192, 0, 0, 255, 0, 0
}; //4
const uint8_t bitmap_6[] PROGMEM = {
0, 127, 0, 1, 255, 192, 3, 255, 240, 15, 255, 248, 15, 255, 248, 31, 255, 252, 63, 195, 252, 63, 129, 254, 127, 0, 254, 127, 0, 248, 126, 0, 0, 126, 0, 0, 254, 0, 0, 254, 63, 0, 254, 255, 224, 255, 255, 240, 255, 255, 248, 255, 255, 252, 255, 255, 252, 255, 195, 254, 255, 1, 254, 255, 0, 255, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 126, 0, 127, 126, 0, 127, 127, 0, 127, 127, 0, 254, 63, 128, 254, 63, 195, 254, 31, 255, 252, 31, 255, 252, 15, 255, 248, 7, 255, 240, 1, 255, 192, 0, 127, 0
}; //3
const uint8_t bitmap_7[] PROGMEM = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 0, 1, 254, 0, 3, 252, 0, 3, 248, 0, 7, 240, 0, 15, 240, 0, 15, 224, 0, 31, 192, 0, 31, 192, 0, 63, 128, 0, 63, 128, 0, 127, 0, 0, 127, 0, 0, 254, 0, 0, 254, 0, 1, 252, 0, 1, 252, 0, 1, 252, 0, 3, 248, 0, 3, 248, 0, 3, 248, 0, 7, 240, 0, 7, 240, 0, 7, 240, 0, 7, 240, 0, 7, 240, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0, 15, 224, 0
}; //3
const uint8_t bitmap_8[] PROGMEM = {
0, 255, 0, 7, 255, 224, 15, 255, 240, 31, 255, 248, 63, 255, 252, 63, 255, 252, 127, 195, 254, 127, 129, 254, 127, 0, 254, 127, 0, 254, 127, 0, 254, 127, 0, 254, 63, 129, 252, 63, 195, 252, 31, 255, 248, 15, 255, 240, 3, 255, 192, 7, 255, 224, 31, 255, 248, 63, 255, 252, 63, 195, 252, 127, 1, 254, 127, 0, 254, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 255, 0, 255, 127, 128, 254, 127, 195, 254, 63, 255, 252, 63, 255, 252, 31, 255, 248, 15, 255, 240, 3, 255, 192, 0, 255, 0
}; //3
const uint8_t bitmap_9[] PROGMEM = {
0, 254, 0, 3, 255, 128, 15, 255, 224, 31, 255, 240, 63, 255, 248, 63, 255, 248, 127, 195, 252, 127, 1, 252, 127, 0, 254, 254, 0, 254, 254, 0, 126, 254, 0, 126, 254, 0, 127, 254, 0, 127, 254, 0, 127, 254, 0, 127, 255, 0, 255, 127, 128, 255, 127, 195, 255, 63, 255, 255, 63, 255, 255, 31, 255, 255, 15, 255, 191, 7, 255, 127, 0, 252, 127, 0, 0, 127, 0, 0, 126, 0, 0, 126, 31, 0, 254, 127, 0, 254, 127, 129, 252, 63, 195, 252, 63, 255, 248, 31, 255, 240, 31, 255, 240, 15, 255, 192, 7, 255, 128, 0, 254, 0
}; //3
void setup () {
Serial.begin(9600);
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2016, 12, 29, 19, 23, 00));
}
}
void loop () {
delay(1000);
DateTime now = rtc.now();
Stunde_String = now.hour();
if (now.dayOfTheWeek() == 0 && now.month() == 3 && now.day() >= 25 && now.hour() ==2 && DST==0){
DST=1;
}
if (now.dayOfTheWeek() == 0 && now.month() == 10 && now.day() >= 25 && now.hour() ==2 && DST==1){
DST=0;
}
if (DST == 1){
Stunde_String = Stunde_String + 1;
}
Serial.print("Clocktime: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(now.dayOfTheWeek());
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
Serial.print("Stunde_String: ");
Serial.print(Stunde_String);
Serial.println();
if (Stunde_String < 10){
Stunde_1 = 0;
Stunde_2 = now.hour();
Serial.print("Stunde < 10 : ");
Serial.print(Stunde_1);
Serial.print(" ");
Serial.print(Stunde_1_tmp);
Serial.print(" ");
Serial.print(Stunde_2);
Serial.print(" ");
Serial.println(Stunde_2_tmp);
}
if (Stunde_String > 9){
//Stunde_String = now.hour();
Stunde_1 = (Stunde_String%100)/10;
Stunde_2 = Stunde_String%10;
Serial.print("Stunde > 9 : ");
Serial.print(Stunde_1);
Serial.print(" ");
Serial.print(Stunde_1_tmp);
Serial.print(" ");
Serial.print(Stunde_2);
Serial.print(" ");
Serial.println(Stunde_2_tmp);
}
if (now.minute() < 10){
Minute_1 = 0;
Minute_2 = now.minute();
}
if (now.minute() > 9){
Minute_String = now.minute();
Minute_1 = (Minute_String%100)/10;
Minute_2 = Minute_String%10;
}
if (Stunde_1_tmp == 2 && Stunde_1 == 0){
Stunde_1_tmp = -1;
}
if (Stunde_2_tmp == 9 && Stunde_2 == 0){
Stunde_2_tmp = -1;
}
if (Minute_1_tmp == 5 && Minute_1 == 0){
Minute_1_tmp = -1;
}
if (Minute_2_tmp == 9 && Minute_2 == 0){
Minute_2_tmp = -1;
}
u8g.firstPage();
do {
//if (Stunde_1_tmp < Stunde_1){
switch (Stunde_1) {
case 0:
u8g.drawBitmapP( 0, 10, 3, 38, bitmap_0);
Serial.println("Switch Stunde_1 = 0");
break;
case 1:
u8g.drawBitmapP( 0, 10, 3, 38, bitmap_1);
Serial.println("Switch Stunde_1 = 1");
break;
case 2:
u8g.drawBitmapP( 0, 10, 3, 38, bitmap_2);
Serial.println("Switch Stunde_1 = 2");
break;
}
Stunde_1_tmp = Stunde_1;
//}
//if (Stunde_2_tmp < Stunde_2){
switch (Stunde_2) {
case 1:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_1);
break;
case 2:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_2);
break;
case 3:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_3);
break;
case 4:
u8g.drawBitmapP( 29, 10, 4, 38, bitmap_4);
break;
case 5:
u8g.drawBitmapP( 29, 10, 4, 38, bitmap_5);
break;
case 6:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_6);
break;
case 7:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_7);
break;
case 8:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_8);
break;
case 9:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_9);
break;
case 0:
u8g.drawBitmapP( 29, 10, 3, 38, bitmap_0);
break;
}
Stunde_2_tmp = Stunde_2;
//}
u8g.drawBitmapP( 59, 20, 1, 20, bitmap_Doppelpunkt);
//if (Minute_1_tmp < Minute_1){
switch (Minute_1) {
case 1:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_1);
break;
case 2:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_2);
break;
case 3:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_3);
break;
case 4:
u8g.drawBitmapP( 72, 10, 4, 38, bitmap_4);
break;
case 5:
u8g.drawBitmapP( 72, 10, 4, 38, bitmap_5);
break;
case 6:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_6);
break;
case 7:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_7);
break;
case 8:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_8);
break;
case 9:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_9);
break;
case 0:
u8g.drawBitmapP( 72, 10, 3, 38, bitmap_0);
break;
}
Minute_1_tmp = Minute_1;
//}
//if (Minute_2_tmp < Minute_2){
switch (Minute_2) {
case 1:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_1);
break;
case 2:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_2);
break;
case 3:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_3);
break;
case 4:
u8g.drawBitmapP( 101, 10, 4, 38, bitmap_4);
break;
case 5:
u8g.drawBitmapP( 101, 10, 4, 38, bitmap_5);
break;
case 6:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_6);
break;
case 7:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_7);
break;
case 8:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_8);
break;
case 9:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_9);
break;
case 0:
u8g.drawBitmapP( 101, 10, 3, 38, bitmap_0);
break;
}
Minute_2_tmp = Minute_2;
//}
} while( u8g.nextPage() );
//delay(1000);
}
Comments