/*H********************************************************************
*
**********************************************************************/
#include "LedControl.h"                  // ALWAYS HAVE TO INCLUDE LIBRARY

//************************* DEFINES ************************************

//************************* PROTOTYPES ************************************
void writeArduinoOn7Segment(); 
void scrollDigits(); 

//************************* VARIABLES ************************************
/*I*******************************************************
 NEED LedControl TO WORK WITH.
 ***** THESE PIN NUMBERS WILL PROBABLY NOT WORK WITH YOUR HARDWARE *****
 PIN 12 IS CONNECTED TO THE DataIn 
 PIN 11 IS CONNECTED TO THE CLK 
 PIN 10 IS CONNECTED TO LOAD 
 HAVE ONLY A SINGLE MAX72XX.
 ********************************************************/
LedControl lc = LedControl( 12, 11, 10, 1 );

// ALWAYS WAIT A BIT BETWEEN UPDATES OF THE DISPLAY
unsigned long delaytime = 250;

/*F********************************************************************
*
**********************************************************************/
void 
setup() 
{
        // MAX72XX IN POWER-SAVING MODE ON STARTUP, HAVE TO DO A WAKEUP CALL
	lc.shutdown( 0, false );
	lc.setIntensity( 0, 8 );            // SET BRIGHTNESS TO A MEDIUM VALUES
	lc.clearDisplay( 0 );                               // AND CLEAR DISPLAY
}
/*F********************************************************************
*
**********************************************************************/
void 
loop() 
{ 
	writeArduinoOn7Segment();
	scrollDigits();
}
/*F********************************************************************
* This method will display characters for word "Arduino" one after other on
 digit 0. 
**********************************************************************/
void 
writeArduinoOn7Segment() 
{
	lc.setChar( 0, 0, 'a', false);
	delay( delaytime );
	lc.setRow( 0, 0, 0x05 );
	delay( delaytime );
	lc.setChar( 0, 0, 'd', false );
	delay( delaytime );
	lc.setRow( 0, 0, 0x1c );
	delay( delaytime );
	lc.setRow( 0, 0, B00010000 );
	delay( delaytime );
	lc.setRow( 0, 0, 0x15 );
	delay( delaytime );
	lc.setRow( 0, 0, 0x1D );
	delay( delaytime );
	lc.clearDisplay( 0 );
	delay( delaytime );
} 
/*F********************************************************************
* This method will scroll all hexa-decimal numbers and letters on display.
 need at least four 7-Segment digits. otherwise it won't really look that good.
**********************************************************************/
void 
scrollDigits() 
{
	for( int i =0; i < 13 ; i++ ) 
	{
		lc.setDigit( 0, 3, i, false );
		lc.setDigit( 0, 2, i +1, false );
		lc.setDigit( 0, 1, i +2, false );
		lc.setDigit( 0, 0, i +3, false );
		delay( delaytime );
	}
	lc.clearDisplay( 0 );
	delay( delaytime );
}