アルディーノ1.0.4にアルディーノUNOコンパチちびでぃーの2を
つないで、ちびでぃーの2付属4ビット並列LCDの上に
ばんとさんのライブラリーを使ってRTCデータを取り出し
表示してみます。そういうスケッチです。
// i2c RTC-8564NB -> Lcd // Using BANT's library by nobcha 05/05/2013 // RTC8564 http://memo.tank.jp/archives/7734 // nobcha #include <LiquidCrystal.h> // Sure 8x2 LCD works with this lib #include <Wire.h> #include <RTC8564.h> RTC8564 RTC; RTC_TIME rtc_time; const char* dayofweek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; /* ChibiDuino2 LCD sample * SETUP: (Hitachi HD44780 compatable LCD) * +5V LCD Vdd pin 2 >>> Gnd LCD Vss pin 1, and R/W pin 5 * LCD RS pin 4 to D9 >>> LCD Enable pin 6 to D8 * LCD D4 pin 11 to D7 >>> LCD D5 pin 12 to D6 * LCD D6 pin 13 to D5 >>> LCD D7 pin 14 to D4 * 10K pot: - ends to +5V and Gnd, wiper to LCD VO pin (pin 3) */ // instanciate the library and pass pins for (RS, Enable, D4, D5, D6, D7) LiquidCrystal lcd(5,6,9,10,11,12); void setup(){ lcd.begin(2,16); // set lib for display size (8x2) lcd.clear(); // clear the screen RTC.begin(); /* 2013年5月5日 0時0分0秒に時刻合わせ */ rtc_time.year = 2013; rtc_time.month = 5; rtc_time.day = 5; rtc_time.hour = 0; rtc_time.min = 0; rtc_time.sec = 0; RTC.adjust( rtc_time ); // これでもOK // RTC.adjust( 2013, 5, 5, 0, 0, 0 ); } void loop(void) { char buf[32]; if(RTC.now(&rtc_time)) { snprintf(buf,16,"%04u-%02u-%02u(%s)", rtc_time.year, rtc_time.month, rtc_time.day, dayofweek[rtc_time.wday]); lcd.setCursor(0,0); lcd.print(buf); snprintf(buf,16," %02u:%02u:%02u", rtc_time.hour, rtc_time.min, rtc_time.sec ); lcd.setCursor(0,1); lcd.print(buf); } delay(1000); }
ばんとさんのライブラリーについていたサンプルスケッチのシリアルの替わりに液晶へ出しただけですので、まだ手習い状態です。