#define OP_NOOP   0
#define OP_DIGIT0 1
#define OP_DIGIT1 2
#define OP_DIGIT2 3
#define OP_DIGIT3 4
#define OP_DIGIT4 5
#define OP_DIGIT5 6
#define OP_DIGIT6 7
#define OP_DIGIT7 8
#define OP_DECODEMODE  9
#define OP_INTENSITY   10
#define OP_SCANLIMIT   11
#define OP_SHUTDOWN    12
#define OP_DISPLAYTEST 15


int CLK=5; // 5 = PD5
int LOAD=6; // 6 = PD6
int DIN=7;  // 7 = PD7
 
byte numberTable[10][8] = {
{0x7C,0xC6,0xCE,0xDE,0xF6,0xE6,0x7C,0x00},// 0
{0x30,0x70,0x30,0x30,0x30,0x30,0xFC,0x00},// 1
{0x78,0xCC,0x0C,0x38,0x60,0xCC,0xFC,0x00},// 2
{0x78,0xCC,0x0C,0x38,0x0C,0xCC,0x78,0x00},// 3
{0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x1E,0x00},// 4
{0xFC,0xC0,0xF8,0x0C,0x0C,0xCC,0x78,0x00},// 5
{0x38,0x60,0xC0,0xF8,0xCC,0xCC,0x78,0x00},// 6
{0xFC,0xCC,0x0C,0x18,0x30,0x30,0x30,0x00},// 7
{0x78,0xCC,0xCC,0x78,0xCC,0xCC,0x78,0x00},// 8
{0x78,0xCC,0xCC,0x7C,0x0C,0x18,0x70,0x00}};// 9


void sendData( byte address, byte data)
{ 
    byte packet[2];
    byte bitmask;
    byte i;
    packet[0]=address;
    packet[1]=data;
     
    for(i=0;i<2;i++)
    for( bitmask=0x80 ; bitmask!=0 ; bitmask=bitmask>>1 )
    {
       if(bitmask & packet[i]) digitalWrite(DIN,1); 
           else digitalWrite(DIN,0);
       
       digitalWrite(CLK, HIGH);
       digitalWrite(CLK, LOW);        
    }
    digitalWrite(LOAD,HIGH); 
    digitalWrite(LOAD,LOW);
}

void setup() {
  // put your setup code here, to run once:
    pinMode(DIN,OUTPUT);
    pinMode(CLK,OUTPUT);
    pinMode(LOAD,OUTPUT);
    digitalWrite(LOAD,LOW);


   sendData(OP_DISPLAYTEST, 0);
   sendData(OP_INTENSITY, 0);
   sendData(OP_SCANLIMIT, 7);
  
   sendData(OP_DECODEMODE, 0);
   sendData(OP_SHUTDOWN, 1);
   for(int i=0;i<8;i++) sendData(i+1, 0b00000000);

}


void showSymbol(int n)
{
   for(int i=0;i<8;i++)   sendData(i+1, numberTable[n][i]);
}


void loop() {
  // put your main code here, to run repeatedly:
   for(int i=0;i<10;i++)
   {
      showSymbol(i);
      delay(400);
   }
   
}