ばんとさんのRTC-8564ライブラリーを動かしてみましょうプロジェクト次ステップです。
LCDを4ビット接続からi2cに芋づる接続のi2cLCDへと変えてみます。
ばんとさんのEXAMPLEにあるスケッチと、エレキジャックの光永さんのストロベリーリナックスi2c液晶を動かすスケッチを合流させました。
これでi2c信号線上でRTCとLCDが「いもづる」関係になりました。
つぎの「おいもちゃん」は何にしましょうか。
// i2c RTC-8564NB -> i2c Lcd // Using BANT's library by nobcha 05/06/2013 // RTC8564 http://memo.tank.jp/archives/7734 // Using MITSUNAGA's library by nobcha 05/06/2013 // i2c_lcd http://n.mtng.org/ele/arduino/i2c.html // nobcha #include <I2CLiquidCrystal.h> #include <Wire.h> #include <RTC8564.h> RTC8564 RTC; RTC_TIME rtc_time; const char* dayofweek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // initialize the library I2CLiquidCrystal lcd(20, true); // | +--- set true if the power suply is 5V, false if it is 3.3V // +-------- contrast (0-63) void setup(){ lcd.begin(16,2); // set lib for display size (16x2) lcd.clear(); // clear the screen RTC.begin(); /* 2013年5月6日 0時0分0秒に時刻合わせ */ rtc_time.year = 2013; rtc_time.month = 5; rtc_time.day = 6; rtc_time.hour = 12; rtc_time.min = 0; rtc_time.sec = 0; RTC.adjust( rtc_time ); // これでもOK // RTC.adjust( 2013, 5, 6, 12, 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); }
nobccha爺は、最近の停滞を抜けるべくアルディーノに手を染めようとしておりますが、今まで頑張ってきたPIC試作はホムペに大体をまとめています。ご参照ください。
特にLCメータとか、アイスクエアドシーなどはインデックスページの左側メニューに入り口があります。