// test program for three cascaded AS1107 // if you got a different configuration you need to // modify the library itself. #include // Arduino pins const byte CsnPin = 2 ; // Chip select (Low active) const byte ClkPin = 3 ; // Serial Clock const byte DataPin = 4 ; // Serial Data byte buffer [ 24 ] ; // Screen buffer (No. of modules * 8) AS1107 matrix ( CsnPin, ClkPin, DataPin ) ; const byte d = 0 ; int count= 1 ; void setup ( ) { matrix. Init ( buffer ) ; matrix. SetScrollText ( " Three 8x8 LED dot matrix modules driven by three AS1107 LED controllers using just four I/O pins of the Arduino for serial data. That is surprisingly fast, look:" , 1 ) ; } void loop ( ) { if ( matrix. TextScroll ( ) ) { delay ( 2000 ) ; for ( int i= 0 ; i<= 7 ; i++ ) { matrix. ShiftUp ( ) ; delay ( 50 ) ; matrix. Update ( ) ; } for ( int i= 0 ; i<= 10 ; i++ ) { CirclePulsate ( ) ; } StarsDown ( ) ; for ( int i= 0 ; i<= 5 ; i++ ) { Rotator1 ( ) ; } StarsRight ( ) ; for ( int i= 0 ; i<=AS1107:: Maxx ; i++ ) { matrix. ShiftRight ( ) ; delay ( 5 ) ; matrix. Update ( ) ; } for ( int i= 1 ; i<= 3 ; i++ ) { bounce ( ) ; } } delay ( 10 ) ; } void CirclePulsate ( ) { for ( int i= 0 ; i<= 15 ; i++ ) { matrix. Clear ( ) ; matrix. DrawEllipse ( AS1107:: Maxx / 2 , 4 ,i,i ) ; matrix. Update ( ) ; delay ( d ) ; } } void StarsDown ( ) { for ( int i= 0 ; i<= 200 ; i++ ) { matrix. ShiftDown ( ) ; matrix. SetLed ( ( byte ) random ( 0 ,AS1107:: Maxx + 1 ) , 0 , 1 ) ; matrix. Update ( ) ; delay ( d ) ; } } void StarsRight ( ) { for ( int i= 0 ; i<= 200 ; i++ ) { matrix. ShiftRight ( ) ; matrix. SetLed ( 0 , ( byte ) random ( 0 ,AS1107:: Maxy + 1 ) , 1 ) ; matrix. Update ( ) ; delay ( d ) ; } } void Rotator1 ( ) { for ( int i= 0 ; i<=AS1107:: Maxx - 1 ; i++ ) { matrix. Clear ( ) ; matrix. DrawLine ( i, 0 ,AS1107:: Maxx -i,AS1107:: Maxy ) ; matrix. Update ( ) ; delay ( d ) ; } for ( int i= 0 ; i<= 6 ; i++ ) { matrix. Clear ( ) ; matrix. DrawLine ( AS1107:: Maxx ,i, 0 , 7 -i ) ; matrix. Update ( ) ; delay ( d ) ; } } void bounce ( ) { int rad= 0 ; float y=random ( 0 ,AS1107:: Maxy + 1 ) ; float x=random ( 0 ,AS1107:: Maxx + 1 ) ; float xacc=random ( 0 , 5 ) - 2 ; float yacc=random ( 0 , 5 ) - 2 ; float yg= 0 . 08 ; if ( xacc == 0 ) xacc == 1 ; if ( yacc == 0 ) yacc == - 1 ; for ( int i= 1 ; i<= 300 ; i++ ) { x+=xacc; y+=yacc; yacc += yg; if ( x >= ( AS1107:: Maxx -rad ) ) { xacc = -xacc* 0 . 9 ; x= AS1107:: Maxx -rad; } else if ( x <= rad ) { xacc = -xacc* 0 . 8 ; x= rad; } if ( y >= ( AS1107:: Maxy -rad ) ) { yacc = - ( yacc* 0 . 80 ) ; y= AS1107:: Maxy -rad; } else if ( y <= rad ) { yacc = -yacc* 0 . 8 ; y= rad; } matrix. Clear ( ) ; matrix. SetLed ( x,y, 1 ) ; matrix. Update ( ) ; } }