kohacraft Lab
/
kc_matrixclock
dot Matrix Led Clock with TLC5940
main.cpp
- Committer:
- kohacraft
- Date:
- 2015-07-28
- Revision:
- 1:7afb65e75dcd
- Parent:
- 0:c61e5f0d54c1
- Child:
- 2:6edd801ae662
File content as of revision 1:7afb65e75dcd:
#include "mbed.h" #include "TLC5940.h" SPI driver( dp2 , dp1 , dp6 ); //mosi , miso , sck DigitalOut vprg = dp4; DigitalOut xlat = dp9; DigitalOut blank = dp10; PwmOut gsclk = dp1; int num_ics = 1; //何個5940がつながっているか #include "font.h" DigitalOut col1 = dp11; DigitalOut col2 = dp13; DigitalOut col3 = dp14; DigitalOut col4 = dp15; DigitalOut col5 = dp16; DigitalOut col6 = dp17; DigitalOut col7 = dp18; DigitalOut col8 = dp26; DigitalIn fastSw = dp28; DigitalIn slowSw = dp25; #define dispTime 10 #define fastCount 1024 #define slowCount 50 //時間の数字をドッドの数字に変換 unsigned char hourDecfont( int num , int colm ) { unsigned char fontTemp = 0; unsigned char fontTemp2 = 0; int numTemp = 0 ; numTemp = num / 10; if( numTemp >0 ) { fontTemp = font[ numTemp ][ colm ]; fontTemp = fontTemp << 5; } numTemp = num - numTemp*10; fontTemp2 = font[ numTemp ][ colm ]; fontTemp2 = fontTemp2 << 2; fontTemp = fontTemp | fontTemp2 | font[ 10 ][ colm ]; return fontTemp; } //数字をドッドの数字に変換 unsigned char decfont( int num , int colm ) { unsigned char fontTemp = 0; int numTemp = 0 ; numTemp = num / 10; fontTemp = font[ numTemp ][ colm ]; fontTemp = fontTemp << 4; numTemp = num - numTemp*10; fontTemp = fontTemp | font[ numTemp ][ colm ]; return fontTemp; } void fontOut( unsigned char font ) { unsigned char mask = 0x01; unsigned char temp = font; col1 = ( temp & mask ); mask = mask << 1; col2 = ( temp & mask ); mask = mask << 1; col3 = ( temp & mask ); mask = mask << 1; col4 = ( temp & mask ); mask = mask << 1; col5 = ( temp & mask ); mask = mask << 1; col6 = ( temp & mask ); mask = mask << 1; col7 = ( temp & mask ); mask = mask << 1; col8 = ( temp & mask ); } int main() { initFont(); setup (driver, vprg, xlat, blank, gsclk, num_ics ); unsigned short LEDS[16]; while(1) { for( int hour =1 ; hour<13 ; hour++ ) { for( int min=0 ; min<60 ; min++) { for( int bright = 0 ; bright < 1024; bright+=2 ) { if( fastSw == 1 ) bright+=fastCount; if( slowSw == 1 ) bright+=slowCount; for( int colmn=0 ; colmn<16 ; colmn++ ) { //PWMをクリア for( int h=0; h<16 ; h++ ) LEDS[h] = 0; LEDS[colmn] = (unsigned short)bright; //必要なピンのみ指定した明るさでON offDisp(blank, gsclk); //PWM強制OFF if( colmn<8 ) fontOut( decfont( min , colmn ) ); else fontOut( hourDecfont( hour , colmn-8 ) ); update_led (driver, xlat, blank, gsclk , LEDS); wait_us(dispTime); } } for( int bright = 1024 ; bright > 0; bright-=2 ) { if( fastSw == 1 ) bright-= fastCount; if( slowSw == 1 ) bright-=slowCount; for( int colmn=0 ; colmn<16 ; colmn++ ) { for( int h=0; h<16 ; h++ ) LEDS[h] = 0; LEDS[colmn] = (unsigned short)bright; offDisp(blank, gsclk); if( colmn<8 ) fontOut( decfont( min , colmn ) ); else fontOut( hourDecfont( hour , colmn-8 ) ); update_led (driver, xlat, blank, gsclk , LEDS); wait_us(dispTime); } } } } } }