// DSP-0401B TEST PROGRAM - SCROLLING TEXT

// pin definitions, using the shiftOut function to communicate with the display

const int SIN = 12;     
const int CLK = 11;   
const int LAT = 10;   
const int BLK = 9;

// character map for upper case letters and numbers 0-9, could be stored in PROGMEM if desired

const word uppercase[26] = { 0x3CB8, 0xBCAC, 0x84AC, 0xAD85, 0x94BC, 0x14B8, 0xB4AC, 0x3838, 
                             0x8585, 0xA80C, 0x4238, 0x802C, 0x2A69, 0x6868, 0xACAC, 0x1CB8,
                             0xECAC, 0x5CB8, 0xC4C4, 0x581,  0xA82C, 0x22A,  0x692A, 0x4242,
                             0x241,  0x8686 };
                            
const word numbers[10] = { 0xAEAE, 0x2A00, 0x9C9C, 0xBC94, 0x3830, 0xB4B4, 0xB4BC, 0x2C80, 0xBCBC, 0xBCB4 };


                               

void setup () {

// set all display control pins to output
  
  pinMode(SIN, OUTPUT);    
  pinMode(CLK, OUTPUT);
  pinMode(LAT, OUTPUT);
  pinMode(BLK, OUTPUT);
  digitalWrite(BLK, HIGH); // blank display during clearing period

  // clear out contents of TLC5926 shift registers by sending empty bytes
  // this prevents any "nonsense" characters from displaying on startup
  
  for(int i = 0; i < 9; i++) {
  digitalWrite(LAT, LOW);
  shiftOut(SIN, CLK, MSBFIRST, 0x00);
  digitalWrite(LAT, HIGH);
  }
    
  analogWrite(BLK, 127); // PWM dimming to reduce current consumption (from over 500mA at full brightness, to under 300mA peak!)
}


void loop () {
  
  // get one character at a time from the array and shift it out to the display in two 8-bit chunks
  
  for(int index = 0; index < 26; index++){                                   
    word character = uppercase[index];
    
    digitalWrite(LAT, LOW);
    shiftOut(SIN, CLK, MSBFIRST, (character >> 8));  //send one byte
    shiftOut(SIN, CLK, MSBFIRST, character);         //then the other 
    digitalWrite(LAT, HIGH);
    delay(500);
  }
  
  for(int index = 0; index < 10; index++){                                   
    word number = numbers[index];
    
    digitalWrite(LAT, LOW);
    shiftOut(SIN, CLK, MSBFIRST, (number >> 8));  //send one byte
    shiftOut(SIN, CLK, MSBFIRST, number);         //then the other 
    digitalWrite(LAT, HIGH);
    delay(500);
  }
  
}

