아두이노 oled 시계 - adu-ino oled sigye

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

아두이노 oled 시계 - adu-ino oled sigye

 

아두이노 oled 시계 - adu-ino oled sigye

97-1.txt

0.00MB

I2C통신을하는 0.91인치 OLED디스플레이에 디지털 시계를 한번 뛰워보자!

 

관련라이브러리(ssd1306)

https://github.com/adafruit/Adafruit_SSD1306

관련라이브러리(DS1302)

https://github.com/Makuna/Rtc/wiki

공유하기

게시글 관리

구독하기파워 유튜버

저작자표시 비영리 변경금지

'프로그래밍 > 아두이노 호작질' 카테고리의 다른 글

[아두이노#110] 내장 EEPROM에 데이터 읽고 쓰고(녹칸다/포로리야공대가자)  (0)2020.10.15[아두이노#109] 열전사 영수증 프린터(Thermal Printer)와 아두이노 연동(튜토리얼)(녹칸다/포로리야공대가자)  (0)2020.10.14[아두이노#96] RTC모듈(DS1302)와 도트매트릭스(MAX7219)로 시계만들기  (0)2020.08.03[아두이노#95] RTC모듈(DS1302)와 FND모듈(TM1637)로 시계만들기  (0)2020.08.03[아두이노#94] RTC모듈 DS1302로 시계만들기(튜토리얼)  (3)2020.08.03

신한카드2,3개월 (5만원↑)
7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22개월 (100만원↑, SK pay 결제 시)
KB국민카드2,3개월 (5만원↑)
8,9,10,11,12,13,14,15,16,17,18,19,20,21,22개월 (100만원↑, SK pay 결제 시)
현대카드2,3개월 (1만원↑)
8,9,10,11,12,13,14,15,16,17,18,19개월 (100만원↑, SK pay 결제 시)
삼성카드2,3개월 (5만원↑)
7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22개월 (100만원↑, SK pay 결제 시)
하나카드2,3,4,5,6,7,8개월 (5만원↑)
롯데카드6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22개월 (100만원↑, SK pay 결제 시)
농협[NH페이]카드2,3,4,5,6,7,8개월 (5만원↑)
12개월 (100만원↑, SK pay 결제 시)

사진과 같은 시계 제작이 필요하신 분은 준비물만 있으면 바로 가능하다.

부품류는 한국에서 모두 구할 수 있지만 가격대가 좀 나가기 때문에

시간적 여유를 두고 알리같은 직구를 이용하길 권한다.

OLED만 봐도 한국은 1~2만원 선이고 알리는 무료배송에 3천원 정도한다.

[준비물]

아두이노 보드

128*64 OLED(SSD1306타입, i2c통신)

RTC(DS1307 또는 DS3231), 시간 오차가 적은 DS3231 추천.(현재 코드는 1307에 맞춰져 있으므로 다른 부품 사용시 코드 변경 필요)

10K옴 저항

버튼

[첨부파일]

​U8glib.h

RTClib.h

상기 2개 라이브러리 설치

code.ino

[아두이노 배선정보]

A4<- 시계,OLED 모듈의 SDA

A5<- 시계,OLED 모듈의 SLC

4<- 버튼 입력용

[시작하기]

첨부파일의 라이브러리를 스케치에 설치한다.

code.ino파일을 열어 업로드한다.

하기 소스는 참고용으로 확인할 것.

코딩은 기초 함수를 썼고 최적화 같은건 난 모른다. 

​소스시작

#include
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

//다른 모델의 OLED라면 u8glib 예제 파일로 가서

//여러 타입 중 자신에게 맞는 타입을 복사,붙여넣기 할것


#include
#include
RTC_DS1307 RTC;

const uint8_t oclimg[] PROGMEM= {
0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00,
0x60, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00,
0x00, 0x00, 0x60, 0x00, 0x3F, 0x04, 0x07, 0xC3, 0x0F, 0xC0, 0xF8, 0x61, 0x80, 0x7F, 0x80, 0x0F,
0xE3, 0x1F, 0xE1, 0xFC, 0x63, 0x80, 0xE1, 0xC0, 0x1C, 0x73, 0x38, 0x73, 0x8E, 0x67, 0x00, 0xC0,
0xC0, 0x18, 0x33, 0x30, 0x33, 0x06, 0x6E, 0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33, 0x00, 0x7C,
0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33, 0x00, 0x7C, 0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33,
0x00, 0x7E, 0x00, 0xC0, 0xC0, 0x18, 0x33, 0x30, 0x33, 0x06, 0x67, 0x00, 0xE1, 0xC0, 0x1C, 0x73,
0x38, 0x73, 0x8E, 0x63, 0x80, 0x7F, 0x80, 0x0F, 0xE3, 0x1F, 0xE1, 0xFC, 0x61, 0xC0, 0x3F, 0x00,
0x07, 0xC3, 0x0F, 0xC0, 0xF8, 0x60, 0xC0,
};
//매시 정각마다 뜨는 o'clock이미지

const uint8_t tikimg[] PROGMEM= {
0xFD, 0x00, 0x40, 0x3F, 0x80, 0x00, 0x80, 0x08, 0x20, 0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x24,
0x21, 0x1C, 0x48, 0x04, 0x1C, 0x38, 0x90, 0x02, 0x21, 0x22, 0x50, 0x04, 0x22, 0x44, 0xA0, 0x02,
0x21, 0x20, 0x60, 0x04, 0x22, 0x40, 0xC0, 0x02, 0x21, 0x20, 0x60, 0x04, 0x22, 0x40, 0xC0, 0x02,
0x21, 0x22, 0x50, 0x04, 0x22, 0x44, 0xA0, 0x24, 0x21, 0x1C, 0x48, 0x04, 0x1C, 0x38, 0x90, 0x08
};
//틱톡 이미지

const uint8_t hamimg[] PROGMEM= {
0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x80, 0x00, 0x02, 0x10, 0x42, 0x02,
0x7F, 0x7C, 0x1C, 0x00, 0x21, 0xC7, 0x1C, 0x04, 0x80, 0x00, 0x02, 0x10, 0x43, 0x06, 0x08, 0x42,
0x22, 0x00, 0x62, 0x28, 0xA2, 0x04, 0x81, 0x11, 0x02, 0x10, 0xA3, 0x06, 0x08, 0x42, 0x41, 0x00,
0x22, 0x28, 0xA2, 0x04, 0x81, 0x11, 0x02, 0x10, 0xA2, 0x8A, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28,
0xA2, 0x04, 0x82, 0xAA, 0xB3, 0xF1, 0x12, 0x8A, 0x08, 0x7C, 0x41, 0x3E, 0x22, 0x28, 0xA2, 0x04,
0x86, 0xAA, 0xA2, 0x11, 0xF2, 0x52, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x44,
0x42, 0x12, 0x0A, 0x22, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x44, 0x42, 0x12,
0x0A, 0x22, 0x08, 0x42, 0x22, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x00, 0x02, 0x12, 0x0A, 0x02,
0x08, 0x42, 0x1C, 0x00, 0x21, 0xC7, 0x1C, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF0,
};

//HAMTRO-1000 이미지(초기 부팅이미지)

const uint8_t minimg[] PROGMEM= {
0x80, 0x93, 0x09, 0x09, 0xFD, 0xF8, 0xC1, 0x93, 0x09, 0x08, 0x21, 0x00, 0xC1, 0x92, 0x89, 0x08,
0x21, 0x00, 0xA2, 0x92, 0x89, 0x08, 0x21, 0x00, 0xA2, 0x92, 0x49, 0x08, 0x21, 0xF8, 0x94, 0x92,
0x49, 0x08, 0x21, 0x00, 0x94, 0x92, 0x29, 0x08, 0x21, 0x00, 0x88, 0x92, 0x29, 0x08, 0x21, 0x00,
0x88, 0x92, 0x19, 0x08, 0x21, 0x00, 0x80, 0x92, 0x18, 0xF0, 0x21, 0xF8,
};

// 시간 설정시 뜨는 문구, 이하 동일

const uint8_t himg[] PROGMEM= {
0x84, 0x38, 0x42, 0x7C, 0x84, 0x44, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42,
0xFC, 0x82, 0x42, 0x7C, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42,
0x84, 0x44, 0x42, 0x42, 0x84, 0x38, 0x3C, 0x42,
};

const uint8_t modeimg[] PROGMEM= {
0x80, 0x87, 0x0F, 0x0F, 0xC0, 0xC1, 0x88, 0x88, 0x88, 0x00, 0xC1, 0x90, 0x48, 0x48, 0x00, 0xA2,
0x90, 0x48, 0x48, 0x00, 0xA2, 0x90, 0x48, 0x4F, 0xC0, 0x94, 0x90, 0x48, 0x48, 0x00, 0x94, 0x90,
0x48, 0x48, 0x00, 0x88, 0x90, 0x48, 0x48, 0x00, 0x88, 0x88, 0x88, 0x88, 0x00, 0x80, 0x87, 0x0F,
0x0F, 0xC0,
};

const uint8_t dayimg[] PROGMEM= {
0xF0, 0x10, 0x82, 0x88, 0x10, 0x82, 0x84, 0x28, 0x44, 0x84, 0x28, 0x44, 0x84, 0x44, 0x28, 0x84,
0x44, 0x28, 0x84, 0x7C, 0x10, 0x84, 0x82, 0x10, 0x88, 0x82, 0x10, 0xF0, 0x82, 0x10,
};

const uint8_t setimg[] PROGMEM= {
0x78, 0xFC, 0xFE, 0x84, 0x80, 0x10, 0x84, 0x80, 0x10, 0x80, 0x80, 0x10, 0x60, 0xFC, 0x10, 0x18,
0x80, 0x10, 0x04, 0x80, 0x10, 0x84, 0x80, 0x10, 0x84, 0x80, 0x10, 0x78, 0xFC, 0x10,
};
const uint8_t yimg[] PROGMEM={
0x82, 0xFC, 0x10, 0xF8, 0x82, 0x80, 0x10, 0x84, 0x44, 0x80, 0x28, 0x84, 0x44, 0x80, 0x28, 0x84,
0x28, 0xFC, 0x44, 0xF8, 0x28, 0x80, 0x44, 0x84, 0x10, 0x80, 0x7C, 0x84, 0x10, 0x80, 0x82, 0x84,
0x10, 0x80, 0x82, 0x84, 0x10, 0xFC, 0x82, 0x84,
};
const uint8_t monimg[] PROGMEM= {
0x80, 0x87, 0x0C, 0x27, 0xF4, 0x20, 0xC1, 0x88, 0x8C, 0x20, 0x84, 0x20, 0xC1, 0x90, 0x4A, 0x20,
0x84, 0x20, 0xA2, 0x90, 0x4A, 0x20, 0x84, 0x20, 0xA2, 0x90, 0x49, 0x20, 0x87, 0xE0, 0x94, 0x90,
0x49, 0x20, 0x84, 0x20, 0x94, 0x90, 0x48, 0xA0, 0x84, 0x20, 0x88, 0x90, 0x48, 0xA0, 0x84, 0x20,
0x88, 0x88, 0x88, 0x60, 0x84, 0x20, 0x80, 0x87, 0x08, 0x60, 0x84, 0x20,
};

const uint8_t cho[] PROGMEM= {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xF8,
0x77, 0xEF, 0x0E, 0xDF, 0x00, 0x00, 0xF7, 0xF7, 0xEE, 0xFE, 0xBF, 0x00, 0x00, 0xEF, 0xF7, 0xED,
0xFE, 0x7F, 0x00, 0x00, 0xEF, 0xF7, 0xED, 0xFE, 0xBF, 0x00, 0x00, 0xF7, 0xF7, 0xEE, 0xFE, 0xDF,
0x00, 0x00, 0xF8, 0x70, 0x6F, 0x0E, 0xEF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x8F, 0x28, 0x00, 0x3F,
0x20, 0xFC, 0x28, 0x81, 0x28, 0x00, 0x08, 0x21, 0x02, 0x54, 0x81, 0x28, 0x00, 0x09, 0xE1, 0x02,
0x54, 0xE1, 0x28, 0x00, 0x0C, 0x20, 0xFC, 0xA2, 0x81, 0xE8, 0x00, 0x12, 0x20, 0x84, 0x00, 0x01,
0x28, 0x7C, 0x21, 0x23, 0xFF, 0x7A, 0x82, 0x28, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x82, 0x28, 0x00,
0x1F, 0xE0, 0xFC, 0x7B, 0x84, 0x28, 0x00, 0x00, 0x21, 0x02, 0x42, 0x88, 0x28, 0x00, 0x00, 0x21,
0x02, 0x7B, 0x80, 0x28, 0x00, 0x00, 0x20, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x8F, 0x28, 0x00, 0x0E,
0x20, 0x10, 0x04, 0x81, 0x28, 0x00, 0x00, 0x20, 0x10, 0x04, 0x81, 0x28, 0x00, 0x3F, 0xA0, 0x10,
0x08, 0x81, 0x28, 0x00, 0x04, 0x20, 0x28, 0xF0, 0x81, 0xE8, 0x00, 0x0A, 0x20, 0x44, 0x00, 0x81,
0x28, 0x7C, 0x31, 0xA1, 0x83, 0x7F, 0x82, 0x28, 0x00, 0x00, 0x20, 0x10, 0x00, 0x82, 0x28, 0x00,
0x3F, 0xA0, 0x10, 0x7F, 0x84, 0x28, 0x00, 0x04, 0x20, 0x10, 0x40, 0x08, 0x28, 0x00, 0x04, 0x23,
0xFF, 0x7F, 0x80, 0x28, 0x00, 0x08, 0x20, 0x00,
};
//시간 설정 완료 대기 시 적용/취소 문구 이미지

const uint8_t week0[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x04, 0x21, 0x04, 0x40, 0x84, 0x40, 0x84,
0x40, 0x84, 0x21, 0x04, 0x1E, 0x04, 0x00, 0x04, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x04, 0x00, 0x04,
0x1F, 0xF8, 0x20, 0x00, 0x20, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//이하 일~토 주일 문구. 금요일은 "불금"으로 표시됨

const uint8_t week1[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x20, 0x84, 0x40, 0x44, 0x20, 0x84,
0x1F, 0x04, 0x00, 0x04, 0xFF, 0xF4, 0x04, 0x04, 0x04, 0x7C, 0x08, 0x04, 0x3F, 0xF8, 0x00, 0x04,
0x1F, 0xF8, 0x20, 0x00, 0x20, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week2[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x84, 0x00, 0x04, 0x00, 0x04, 0xFF, 0xE4,
0x00, 0x04, 0x3F, 0x84, 0x40, 0x44, 0x40, 0x44, 0x40, 0x47, 0x3F, 0x84, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0xFF, 0xF4, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week3[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x80,
0x04, 0x40, 0x18, 0x30, 0x60, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week4[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFC, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04,
0x7F, 0xFC, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF8,
0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week5[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x40, 0x85, 0xFC, 0x40,
0x80, 0x02, 0x7F, 0x98, 0x02, 0x40, 0x80, 0x02, 0x3F, 0x00, 0x02, 0x00, 0x00, 0x04, 0xFF, 0xC7,
0xFF, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x01, 0xFE, 0x00, 0x81, 0x02,
0x3F, 0x81, 0x02, 0x40, 0x01, 0x02, 0x40, 0x01, 0x02, 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const uint8_t week6[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFC, 0x40, 0x00,
0x40, 0x00, 0x7F, 0xFC, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x3F, 0xFC, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

int gmnt=0;
int gday=0;
int nowy=0;


int bt_pin=4;

//버튼 연결 핀

int h12=1;

//시간 표시모드 전환. 1이면 1~12시,   0이면 0~23시 표시.


int nowh=0;
int nowm=0;
int nows=0;
int sec=1;
String hh="";
String mm="";
int fps=0;
int bt_c=0;
int stat=2;
String imnt="";
String idays="";
int inputt=0;
const char* daymsgs[8]={
" I LUV U","Cheer up","My baby","Hey YOU","I Like U","Be Happy"," Hello :)","Wake Up!"
};
//초기 부팅 후 뜨는 메세지. 총 8개이며 8일 주기로 매일 바뀜

void setup() {
Wire.begin();
RTC.begin();
DateTime now=RTC.now();
//RTC.adjust(DateTime(2017, 02, 28, 8, 59, 40));
//RTC.adjust(DateTime(__DATE__,__TIME__));

//초기 날짜 세팅부분. 날짜를 직접 입력하거나 연결된 컴퓨터의 날짜 정보를 가져옴

//처음 한번만 실행하고 그 이후로는 주석 처리 후 다시 업로드

pinMode(bt_pin,INPUT);

u8g.setFont(u8g_font_fub20);
//폰트 설정.세로 20크기로 사용됨. 폰트를 바꾸면 각 숫자의 좌표도 일일이 바꿔야함.

u8g.firstPage();
do{
u8g.drawBitmapP(8, 27, 14, 15, hamimg);

//초기 HAMTRO-1000 로고 출력
}while(u8g.nextPage());

delay(2500);

int daymsg=now.day()%8;
for(int i=0; i<10;i++){

u8g.firstPage();
do{
u8g.drawStr(0, i*4+6, daymsgs[daymsg]);

//오늘 날짜 기반으로 8개의 메세지중 하나를 띄움. 좌표를 변화시켜 위에서 아래로 내려오는 효과.


}while(u8g.nextPage());
delay(50);
}
delay(4000);

}
void loop() {

DateTime now=RTC.now();

if(stat==1){

//일상 시계 표시 모드

nowh=now.hour();
nowm=now.minute();
nows=now.second();

if(nowm==0 && nows<5){
//매시 정각마다 띄우는 오클락

  nowh=nowh%12;
if(nowh==0){
nowh=12;
}

hh=String(nowh,DEC);
const char* chh=(const char*) hh.c_str();
u8g.firstPage();
do{
if(nowh<10){
u8g.drawStr(20,52, chh);
}else{
u8g.drawStr(8,52, chh);
}
u8g.drawBitmapP(49, 37, 9, 15, oclimg);
u8g.drawBitmapP(36, 13, 8, 8, tikimg);
}while(u8g.nextPage());

}else{

if(h12==1){
nowh=nowh%12;
if(nowh==0){
nowh=12;
}
}

if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{

u8g.drawBitmapP(36, 13, 8, 8, tikimg);

u8g.drawStr(27,52, chh);
if(sec==1){
u8g.drawStr(60,48, ":");
}

u8g.drawStr(73,52, cmm);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
if(digitalRead(bt_pin)==HIGH){
bt_c++;

}else{
if(bt_c>8){
//go adjust

stat=13;
nowh=now.hour();
nowy=now.year();
if(nowy<2017){
nowy=2017;
}
}else if(bt_c>0){
//view date
stat=2;
}
bt_c=0;
}
}
delay(50);
}

if(stat==2){
//버튼 짧게 클릭시 날짜 보기로 전환

int week=now.dayOfTheWeek();

gmnt=now.month();
gday=now.day();
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}

int wx=98;
int wy=38;

const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawStr(14,60,mnt);
u8g.drawStr(47,60, "/");
u8g.drawStr(60,60,days);
u8g.drawStr(23,30, "Today");
if(week==0){
u8g.drawBitmapP(wx, wy, 2, 24, week0);
}else if(week==1){
u8g.drawBitmapP(wx, wy, 2, 24, week1);
}else if(week==2){
u8g.drawBitmapP(wx, wy, 2, 24, week2);
}else if(week==3){
u8g.drawBitmapP(wx, wy, 2, 24, week3);
}else if(week==4){
u8g.drawBitmapP(wx, wy, 2, 24, week4);
}else if(week==5){
u8g.drawBitmapP(wx, wy, 3, 24, week5);
}else{
u8g.drawBitmapP(wx, wy, 2, 24, week6);
}
}while(u8g.nextPage());
delay(2000);
stat=1;
}

if(stat==13){
//set year
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c==1){
nowy++;
if(nowy>2099){
nowy=2017;
}
}
if(bt_c>1){
bt_c=0;
}
}else{
bt_c=0;
}
String snowy=String(nowy,DEC);
const char* cnowy=(const char*) snowy.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 4, 10, yimg);
u8g.drawStr(36,50,cnowy);
}while(u8g.nextPage());
inputt++;
if(inputt==20){
inputt=0;
stat=14;
gmnt=now.month();
gday=now.day();
}
delay(50);
}

if(stat==14){
//set month
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c==1){
gmnt++;
if(gmnt>12){
gmnt=1;
}
}
}else{
bt_c=0;
}
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}
const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 6, 10, monimg);
if(sec==1){
u8g.drawStr(27,50, mnt);
}
u8g.drawStr(60,50, "/");
u8g.drawStr(73,50, days);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=15;
}
delay(50);
}

if(stat==15){
//set day
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c>1){
bt_c=0;
}
if(bt_c==1){
gday++;
if(gday>31){
gday=1;
}

}
}else{
bt_c=0;
}
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}
const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 3, 10, dayimg);
u8g.drawStr(27,50, mnt);

u8g.drawStr(60,50, "/");
if(sec==1){
u8g.drawStr(73,50, days);
}
}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=3;
}
delay(50);
}

if(stat==3){
//set12/24
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c==1){
if(h12==1){
h12=0;
}else{
h12=1;
}
}
}else{
bt_c=0;
}
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 5, 10, modeimg);
if(h12==1){
u8g.drawStr(12,50, "12 Hour");
}else{
u8g.drawStr(12,50, "24 Hour");

}
}while(u8g.nextPage());

inputt++;
if(inputt==20){
inputt=0;
stat=4;
}

}

if(stat==4){
//set hour
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c==1){
nowh++;
if(nowh>23){
nowh=0;
}
}
}else{
bt_c=0;
}
if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 4, 10, himg);
if(sec==1){
u8g.drawStr(27,50, chh);
}
u8g.drawStr(60,46, ":");
u8g.drawStr(73,50, cmm);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=5;
}
delay(50);
}

if(stat==5){
//set min
if(digitalRead(bt_pin)==HIGH){
inputt=0;
bt_c++;
if(bt_c==1){
nowm++;
if(nowm>59){
nowm=0;
}
}
if(bt_c>1){
bt_c=0;
}
}else{
bt_c=0;
}
if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 6, 10, minimg);
u8g.drawStr(27,50, chh);

u8g.drawStr(60,46, ":");
if(sec==1){
u8g.drawStr(73,50, cmm);
}

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=6;
u8g.firstPage();
do{
u8g.drawBitmapP(36, 9, 7, 40, cho);
}while(u8g.nextPage());
}
delay(50);
}
if(stat==6){
if(digitalRead(bt_pin)==HIGH){
bt_c++;
}else{
if(bt_c>10){
stat=1;
}else if(bt_c>0){
RTC.adjust(DateTime(nowy, gmnt, gday, nowh, nowm, 00));
stat=1;
}
bt_c=0;
}

delay(50);

}

소스 끝

다음은 회로도 상 버튼 저항이 필요없도록 수정된 코드입니다.

회로도에 보이는 저항은 제거하시고,

버튼의 한쪽다리는 GND

나머지 다리는 아두이노의 4번핀으로 연결하시면 됩니다.

#include
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

//다른 모델의 OLED라면 u8glib 예제 파일로 가서

//여러 타입 중 자신에게 맞는 타입을 복사,붙여넣기 할것


#include
#include
RTC_DS1307 RTC;

const uint8_t oclimg[] PROGMEM= {
0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00,
0x60, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00,
0x00, 0x00, 0x60, 0x00, 0x3F, 0x04, 0x07, 0xC3, 0x0F, 0xC0, 0xF8, 0x61, 0x80, 0x7F, 0x80, 0x0F,
0xE3, 0x1F, 0xE1, 0xFC, 0x63, 0x80, 0xE1, 0xC0, 0x1C, 0x73, 0x38, 0x73, 0x8E, 0x67, 0x00, 0xC0,
0xC0, 0x18, 0x33, 0x30, 0x33, 0x06, 0x6E, 0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33, 0x00, 0x7C,
0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33, 0x00, 0x7C, 0x00, 0xC0, 0xC0, 0x18, 0x03, 0x30, 0x33,
0x00, 0x7E, 0x00, 0xC0, 0xC0, 0x18, 0x33, 0x30, 0x33, 0x06, 0x67, 0x00, 0xE1, 0xC0, 0x1C, 0x73,
0x38, 0x73, 0x8E, 0x63, 0x80, 0x7F, 0x80, 0x0F, 0xE3, 0x1F, 0xE1, 0xFC, 0x61, 0xC0, 0x3F, 0x00,
0x07, 0xC3, 0x0F, 0xC0, 0xF8, 0x60, 0xC0,
};
 //매시 정각마다 뜨는 o'clock이미지

const uint8_t tikimg[] PROGMEM= {
0xFD, 0x00, 0x40, 0x3F, 0x80, 0x00, 0x80, 0x08, 0x20, 0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x24,
0x21, 0x1C, 0x48, 0x04, 0x1C, 0x38, 0x90, 0x02, 0x21, 0x22, 0x50, 0x04, 0x22, 0x44, 0xA0, 0x02,
0x21, 0x20, 0x60, 0x04, 0x22, 0x40, 0xC0, 0x02, 0x21, 0x20, 0x60, 0x04, 0x22, 0x40, 0xC0, 0x02,
0x21, 0x22, 0x50, 0x04, 0x22, 0x44, 0xA0, 0x24, 0x21, 0x1C, 0x48, 0x04, 0x1C, 0x38, 0x90, 0x08
};
 //틱톡 이미지


const uint8_t hamimg[] PROGMEM= {
0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x80, 0x00, 0x02, 0x10, 0x42, 0x02,
0x7F, 0x7C, 0x1C, 0x00, 0x21, 0xC7, 0x1C, 0x04, 0x80, 0x00, 0x02, 0x10, 0x43, 0x06, 0x08, 0x42,
0x22, 0x00, 0x62, 0x28, 0xA2, 0x04, 0x81, 0x11, 0x02, 0x10, 0xA3, 0x06, 0x08, 0x42, 0x41, 0x00,
0x22, 0x28, 0xA2, 0x04, 0x81, 0x11, 0x02, 0x10, 0xA2, 0x8A, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28,
0xA2, 0x04, 0x82, 0xAA, 0xB3, 0xF1, 0x12, 0x8A, 0x08, 0x7C, 0x41, 0x3E, 0x22, 0x28, 0xA2, 0x04,
0x86, 0xAA, 0xA2, 0x11, 0xF2, 0x52, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x44,
0x42, 0x12, 0x0A, 0x22, 0x08, 0x42, 0x41, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x44, 0x42, 0x12,
0x0A, 0x22, 0x08, 0x42, 0x22, 0x00, 0x22, 0x28, 0xA2, 0x04, 0x80, 0x00, 0x02, 0x12, 0x0A, 0x02,
0x08, 0x42, 0x1C, 0x00, 0x21, 0xC7, 0x1C, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF0,
};

//HAMTRO-1000 이미지(초기 부팅이미지)

const uint8_t minimg[] PROGMEM= {
0x80, 0x93, 0x09, 0x09, 0xFD, 0xF8, 0xC1, 0x93, 0x09, 0x08, 0x21, 0x00, 0xC1, 0x92, 0x89, 0x08,
0x21, 0x00, 0xA2, 0x92, 0x89, 0x08, 0x21, 0x00, 0xA2, 0x92, 0x49, 0x08, 0x21, 0xF8, 0x94, 0x92,
0x49, 0x08, 0x21, 0x00, 0x94, 0x92, 0x29, 0x08, 0x21, 0x00, 0x88, 0x92, 0x29, 0x08, 0x21, 0x00,
0x88, 0x92, 0x19, 0x08, 0x21, 0x00, 0x80, 0x92, 0x18, 0xF0, 0x21, 0xF8,
};

// 시간 설정시 뜨는 문구, 이하 동일

const uint8_t himg[] PROGMEM= {
0x84, 0x38, 0x42, 0x7C, 0x84, 0x44, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42,
0xFC, 0x82, 0x42, 0x7C, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42, 0x84, 0x82, 0x42, 0x42,
0x84, 0x44, 0x42, 0x42, 0x84, 0x38, 0x3C, 0x42,
};

const uint8_t modeimg[] PROGMEM= {
0x80, 0x87, 0x0F, 0x0F, 0xC0, 0xC1, 0x88, 0x88, 0x88, 0x00, 0xC1, 0x90, 0x48, 0x48, 0x00, 0xA2,
0x90, 0x48, 0x48, 0x00, 0xA2, 0x90, 0x48, 0x4F, 0xC0, 0x94, 0x90, 0x48, 0x48, 0x00, 0x94, 0x90,
0x48, 0x48, 0x00, 0x88, 0x90, 0x48, 0x48, 0x00, 0x88, 0x88, 0x88, 0x88, 0x00, 0x80, 0x87, 0x0F,
0x0F, 0xC0,
};

const uint8_t dayimg[] PROGMEM= {
0xF0, 0x10, 0x82, 0x88, 0x10, 0x82, 0x84, 0x28, 0x44, 0x84, 0x28, 0x44, 0x84, 0x44, 0x28, 0x84,
0x44, 0x28, 0x84, 0x7C, 0x10, 0x84, 0x82, 0x10, 0x88, 0x82, 0x10, 0xF0, 0x82, 0x10,
};

const uint8_t setimg[] PROGMEM= {
0x78, 0xFC, 0xFE, 0x84, 0x80, 0x10, 0x84, 0x80, 0x10, 0x80, 0x80, 0x10, 0x60, 0xFC, 0x10, 0x18,
0x80, 0x10, 0x04, 0x80, 0x10, 0x84, 0x80, 0x10, 0x84, 0x80, 0x10, 0x78, 0xFC, 0x10,
};
const uint8_t yimg[] PROGMEM={
0x82, 0xFC, 0x10, 0xF8, 0x82, 0x80, 0x10, 0x84, 0x44, 0x80, 0x28, 0x84, 0x44, 0x80, 0x28, 0x84,
0x28, 0xFC, 0x44, 0xF8, 0x28, 0x80, 0x44, 0x84, 0x10, 0x80, 0x7C, 0x84, 0x10, 0x80, 0x82, 0x84,
0x10, 0x80, 0x82, 0x84, 0x10, 0xFC, 0x82, 0x84,
};
const uint8_t monimg[] PROGMEM= {
0x80, 0x87, 0x0C, 0x27, 0xF4, 0x20, 0xC1, 0x88, 0x8C, 0x20, 0x84, 0x20, 0xC1, 0x90, 0x4A, 0x20,
0x84, 0x20, 0xA2, 0x90, 0x4A, 0x20, 0x84, 0x20, 0xA2, 0x90, 0x49, 0x20, 0x87, 0xE0, 0x94, 0x90,
0x49, 0x20, 0x84, 0x20, 0x94, 0x90, 0x48, 0xA0, 0x84, 0x20, 0x88, 0x90, 0x48, 0xA0, 0x84, 0x20,
0x88, 0x88, 0x88, 0x60, 0x84, 0x20, 0x80, 0x87, 0x08, 0x60, 0x84, 0x20,
};

const uint8_t cho[] PROGMEM= {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xF8,
0x77, 0xEF, 0x0E, 0xDF, 0x00, 0x00, 0xF7, 0xF7, 0xEE, 0xFE, 0xBF, 0x00, 0x00, 0xEF, 0xF7, 0xED,
0xFE, 0x7F, 0x00, 0x00, 0xEF, 0xF7, 0xED, 0xFE, 0xBF, 0x00, 0x00, 0xF7, 0xF7, 0xEE, 0xFE, 0xDF,
0x00, 0x00, 0xF8, 0x70, 0x6F, 0x0E, 0xEF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x8F, 0x28, 0x00, 0x3F,
0x20, 0xFC, 0x28, 0x81, 0x28, 0x00, 0x08, 0x21, 0x02, 0x54, 0x81, 0x28, 0x00, 0x09, 0xE1, 0x02,
0x54, 0xE1, 0x28, 0x00, 0x0C, 0x20, 0xFC, 0xA2, 0x81, 0xE8, 0x00, 0x12, 0x20, 0x84, 0x00, 0x01,
0x28, 0x7C, 0x21, 0x23, 0xFF, 0x7A, 0x82, 0x28, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x82, 0x28, 0x00,
0x1F, 0xE0, 0xFC, 0x7B, 0x84, 0x28, 0x00, 0x00, 0x21, 0x02, 0x42, 0x88, 0x28, 0x00, 0x00, 0x21,
0x02, 0x7B, 0x80, 0x28, 0x00, 0x00, 0x20, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x8F, 0x28, 0x00, 0x0E,
0x20, 0x10, 0x04, 0x81, 0x28, 0x00, 0x00, 0x20, 0x10, 0x04, 0x81, 0x28, 0x00, 0x3F, 0xA0, 0x10,
0x08, 0x81, 0x28, 0x00, 0x04, 0x20, 0x28, 0xF0, 0x81, 0xE8, 0x00, 0x0A, 0x20, 0x44, 0x00, 0x81,
0x28, 0x7C, 0x31, 0xA1, 0x83, 0x7F, 0x82, 0x28, 0x00, 0x00, 0x20, 0x10, 0x00, 0x82, 0x28, 0x00,
0x3F, 0xA0, 0x10, 0x7F, 0x84, 0x28, 0x00, 0x04, 0x20, 0x10, 0x40, 0x08, 0x28, 0x00, 0x04, 0x23,
0xFF, 0x7F, 0x80, 0x28, 0x00, 0x08, 0x20, 0x00,
};
 //시간 설정 완료 대기 시 적용/취소 문구 이미지

const uint8_t week0[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x04, 0x21, 0x04, 0x40, 0x84, 0x40, 0x84,
0x40, 0x84, 0x21, 0x04, 0x1E, 0x04, 0x00, 0x04, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x04, 0x00, 0x04,
0x1F, 0xF8, 0x20, 0x00, 0x20, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 //이하 일~토 주일 문구. 금요일은 "불금"으로 표시됨

const uint8_t week1[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x20, 0x84, 0x40, 0x44, 0x20, 0x84,
0x1F, 0x04, 0x00, 0x04, 0xFF, 0xF4, 0x04, 0x04, 0x04, 0x7C, 0x08, 0x04, 0x3F, 0xF8, 0x00, 0x04,
0x1F, 0xF8, 0x20, 0x00, 0x20, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week2[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x84, 0x00, 0x04, 0x00, 0x04, 0xFF, 0xE4,
0x00, 0x04, 0x3F, 0x84, 0x40, 0x44, 0x40, 0x44, 0x40, 0x47, 0x3F, 0x84, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0xFF, 0xF4, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week3[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x80,
0x04, 0x40, 0x18, 0x30, 0x60, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week4[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFC, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04,
0x7F, 0xFC, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF8,
0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t week5[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x40, 0x85, 0xFC, 0x40,
0x80, 0x02, 0x7F, 0x98, 0x02, 0x40, 0x80, 0x02, 0x3F, 0x00, 0x02, 0x00, 0x00, 0x04, 0xFF, 0xC7,
0xFF, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x01, 0xFE, 0x00, 0x81, 0x02,
0x3F, 0x81, 0x02, 0x40, 0x01, 0x02, 0x40, 0x01, 0x02, 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const uint8_t week6[] PROGMEM= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFC, 0x40, 0x00,
0x40, 0x00, 0x7F, 0xFC, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x3F, 0xFC, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

int gmnt=0;
int gday=0;
int nowy=0;


int bt_pin=4;

//버튼 연결 핀

int h12=1;

//시간 표시모드 전환. 1이면 1~12시,   0이면 0~23시 표시.


int nowh=0;
int nowm=0;
int nows=0;
int sec=1;
String hh="";
String mm="";
int fps=0;
int bt_c=0;
int stat=2;
String imnt="";
String idays="";
int inputt=0;
const char* daymsgs[8]={
" I LUV U","Cheer up","My baby","Hey YOU","I Like U","Be Happy"," Hello :)","Wake Up!"
};
 //초기 부팅 후 뜨는 메세지. 총 8개이며 8일 주기로 매일 바뀜


void setup() {
Wire.begin();
RTC.begin();
DateTime now=RTC.now();
//RTC.adjust(DateTime(2017, 02, 28, 8, 59, 40));
//RTC.adjust(DateTime(__DATE__,__TIME__));

//초기 날짜 세팅부분. 날짜를 직접 입력하거나 연결된 컴퓨터의 날짜 정보를 가져옴

//처음 한번만 실행하고 그 이후로는 주석 처리 후 다시 업로드

pinMode(bt_pin,INPUT_PULLUP);
u8g.setFont(u8g_font_fub20);
 //폰트 설정.세로 20크기로 사용됨. 폰트를 바꾸면 각 숫자의 좌표도 일일이 바꿔야함.

u8g.firstPage();
do{
u8g.drawBitmapP(8, 27, 14, 15, hamimg);

//초기 HAMTRO-1000 로고 출력
}while(u8g.nextPage());

delay(2500);

int daymsg=now.day()%8;
for(int i=0; i<10;i++){

u8g.firstPage();
do{
u8g.drawStr(0, i*4+6, daymsgs[daymsg]);

//오늘 날짜 기반으로 8개의 메세지중 하나를 띄움. 좌표를 변화시켜 위에서 아래로 내려오는 효과.


}while(u8g.nextPage());
delay(50);
}
delay(4000);

}
void loop() {

DateTime now=RTC.now();


if(stat==1){

//일상 시계 표시 모드

nowh=now.hour();
nowm=now.minute();
nows=now.second();


if(nowm==0 && nows<5){
 //매시 정각마다 띄우는 오클락

  nowh=nowh%12;
if(nowh==0){
 nowh=12;
}

hh=String(nowh,DEC);
const char* chh=(const char*) hh.c_str();
u8g.firstPage();
do{
 if(nowh<10){
 u8g.drawStr(20,52, chh);
 }else{
 u8g.drawStr(8,52, chh);
 }
 u8g.drawBitmapP(49, 37, 9, 15, oclimg);
 u8g.drawBitmapP(36, 13, 8, 8, tikimg);
 }while(u8g.nextPage());

}else{


if(h12==1){
nowh=nowh%12;
if(nowh==0){
 nowh=12;
}
}

if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{

u8g.drawBitmapP(36, 13, 8, 8, tikimg);

u8g.drawStr(27,52, chh);
if(sec==1){
u8g.drawStr(60,48, ":");
}

u8g.drawStr(73,52, cmm);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
if(digitalRead(bt_pin)==LOW){
bt_c++;

}else{
if(bt_c>8){
//go adjust

stat=13;
nowh=now.hour();
nowy=now.year();
if(nowy<2017){
nowy=2017;
}
}else if(bt_c>0){
//view date
stat=2;
}
bt_c=0;
}
}
delay(50);
}


if(stat==2){
//버튼 짧게 클릭시 날짜 보기로 전환

int week=now.dayOfTheWeek();

gmnt=now.month();
gday=now.day();
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}

int wx=98;
int wy=38;


const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawStr(14,60,mnt);
u8g.drawStr(47,60, "/");
u8g.drawStr(60,60,days);
u8g.drawStr(23,30, "Today");
if(week==0){
u8g.drawBitmapP(wx, wy, 2, 24, week0);
}else if(week==1){
u8g.drawBitmapP(wx, wy, 2, 24, week1);
}else if(week==2){
u8g.drawBitmapP(wx, wy, 2, 24, week2);
}else if(week==3){
u8g.drawBitmapP(wx, wy, 2, 24, week3);
}else if(week==4){
u8g.drawBitmapP(wx, wy, 2, 24, week4);
}else if(week==5){
u8g.drawBitmapP(wx, wy, 3, 24, week5);
}else{
u8g.drawBitmapP(wx, wy, 2, 24, week6);
}
}while(u8g.nextPage());
delay(2000);
stat=1;
}


if(stat==13){
//set year
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c==1){
nowy++;
if(nowy>2099){
nowy=2017;
}
}
if(bt_c>1){
bt_c=0;
}
}else{
bt_c=0;
}
String snowy=String(nowy,DEC);
const char* cnowy=(const char*) snowy.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 4, 10, yimg);
u8g.drawStr(36,50,cnowy);
}while(u8g.nextPage());
inputt++;
if(inputt==20){
inputt=0;
stat=14;
gmnt=now.month();
gday=now.day();
}
delay(50);
}

if(stat==14){
//set month
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c==1){
gmnt++;
if(gmnt>12){
gmnt=1;
}
}
}else{
bt_c=0;
}
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}
const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 6, 10, monimg);
if(sec==1){
u8g.drawStr(27,50, mnt);
}
u8g.drawStr(60,50, "/");
u8g.drawStr(73,50, days);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=15;
}
delay(50);
}


if(stat==15){
//set day
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c>1){
bt_c=0;
}
if(bt_c==1){
gday++;
if(gday>31){
gday=1;
}

}
}else{
bt_c=0;
}
if(gmnt<10){
imnt="0" + String(gmnt,DEC);
}else{
imnt=String(gmnt,DEC);
}
if(gday<10){
idays="0" + String(gday,DEC);
}else{
idays=String(gday,DEC);
}
const char* mnt=(const char*) imnt.c_str();
const char* days=(const char*) idays.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 3, 10, dayimg);
u8g.drawStr(27,50, mnt);

u8g.drawStr(60,50, "/");
if(sec==1){
u8g.drawStr(73,50, days);
}
}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=3;
}
delay(50);
}

if(stat==3){
//set12/24
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c==1){
if(h12==1){
h12=0;
}else{
h12=1;
}
}
}else{
bt_c=0;
}
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 5, 10, modeimg);
if(h12==1){
u8g.drawStr(12,50, "12 Hour");
}else{
u8g.drawStr(12,50, "24 Hour");

}
}while(u8g.nextPage());

inputt++;
if(inputt==20){
inputt=0;
stat=4;
}

}


if(stat==4){
//set hour
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c==1){
nowh++;
if(nowh>23){
nowh=0;
}
}
}else{
bt_c=0;
}
if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 4, 10, himg);
if(sec==1){
u8g.drawStr(27,50, chh);
}
u8g.drawStr(60,46, ":");
u8g.drawStr(73,50, cmm);

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=5;
}
delay(50);
}

if(stat==5){
//set min
if(digitalRead(bt_pin)==LOW){
inputt=0;
bt_c++;
if(bt_c==1){
nowm++;
if(nowm>59){
nowm=0;
}
}
if(bt_c>1){
bt_c=0;
}
}else{
bt_c=0;
}
if(nowh<10){
hh="0" + String(nowh,DEC);
}else{
hh=String(nowh,DEC);
}
if(nowm<10){
mm="0" + String(nowm,DEC);
}else{
mm=String(nowm,DEC);
}
const char* chh=(const char*) hh.c_str();
const char* cmm=(const char*) mm.c_str();
u8g.firstPage();
do{
u8g.drawBitmapP(27, 10, 3, 10, setimg);
u8g.drawBitmapP(60, 10, 6, 10, minimg);
u8g.drawStr(27,50, chh);

u8g.drawStr(60,46, ":");
if(sec==1){
u8g.drawStr(73,50, cmm);
}

}while(u8g.nextPage());
fps++;
if(fps==3){
fps=0;

if(sec==1){
sec=0;
}else{
sec=1;

}
}
inputt++;
if(inputt==20){
inputt=0;
stat=6;
u8g.firstPage();
do{
u8g.drawBitmapP(36, 9, 7, 40, cho);
}while(u8g.nextPage());
}
delay(50);
}
if(stat==6){
if(digitalRead(bt_pin)==LOW){
bt_c++;
}else{
if(bt_c>10){
stat=1;
}else if(bt_c>0){
RTC.adjust(DateTime(nowy, gmnt, gday, nowh, nowm, 00));
stat=1;
}
bt_c=0;
}

delay(50);

}
}