Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:5577d93280da
- Parent:
- 0:c872b97ce7ea
- Child:
- 2:9c618daf65f5
diff -r c872b97ce7ea -r 5577d93280da main.cpp
--- a/main.cpp Tue Aug 11 00:56:37 2015 +0000
+++ b/main.cpp Tue Aug 11 05:02:15 2015 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
#include "font.h"
-
+#include "ds3231.h"
#include "TLC5940.h"
int num_ics = 1; //何個TLC5940がつながっているか
@@ -13,16 +13,18 @@
DigitalOut col7 = dp18;
DigitalOut col8 = dp26;
+InterruptIn secInt(dp1); //ピンの変化検出
+
DigitalIn fastSw = dp28;
DigitalIn slowSw = dp25;
-
#define brightMax 4095
-DigitalOut led = dp28;
-
+Ds3231 rtc( dp5 , dp27 ); //リアルタイムクロック
int sec = 0;
int min = 0;//
int hour =1;//
+bool minChange = 0;//
+bool hourChange = 0;//
//時間の数字をドッドの数字に変換
unsigned char hourDecfont( int num , int colm )
@@ -109,25 +111,65 @@
col8 = 1;
else
col8 = 0;
-
+}
-
+//1秒のカウントアップ
+void secUp()
+{
+ sec++;
+ if( sec >= 60 )
+ {
+ sec = 0;
+ min++;
+ minChange = 1;
+ }
+ if( min >= 60 )
+ {
+ min = 0;
+ hour++;
+ hourChange = 1;
+ }
+ if( hour >= 12 )
+ {
+ hour = 0;
+ hourChange = 1;
+ }
+
}
int main() {
- led = 0;
+
+ //フォント初期化
initFont();
+
+ //TLC5940初期設定
setup ( num_ics );
- led = 1;
+
+ //DS3231初期設定
+ ds3231_cntl_stat_t data = {0,0}; //SQWに1秒のクロックを出力する
+ rtc.set_cntl_stat_reg( data );
+
+ secInt.rise( &secUp ); //RTCの1秒クロックでカウントアップする
+ wait(0.1);
+ //DS3231に記録されている時間を読み出す
+ ds3231_time_t time;
+ int value = rtc.get_time(&time);
+ hour = time.hours;
+ if( hour > 12 )
+ hour -=12;
+ min = time.minutes;
+ sec = time.seconds;
+
+ //スイッチの初期化
+ fastSw.mode(PullDown);
+ slowSw.mode(PullDown);
+
+
unsigned short LEDS[16];
while(1) {
- if( led == 1 )
- led = 0;
- else
- led = 1;
//16行分ダイナミック点灯させる
for( int colmn=0 ; colmn<16 ; colmn++ )
@@ -138,9 +180,9 @@
LEDS[h] = 0;
LEDS[colmn] = (unsigned short)brightMax;
if( colmn<8 )
- fontOut( decfont( min , colmn ) );
+ fontOut( decfont( sec , colmn ) );
else
- fontOut( hourDecfont( hour , colmn-8 ) );
+ fontOut( hourDecfont( min , colmn-8 ) );
update_led ( LEDS);