Interfacing to LASCAR EM32-4-LED 4-Digit Display

I needed to interface with this device for a work project: http://www.lascarelectronics.com/temperaturedatalogger.php?datalogger=110

Figuring out the serial control was pretty straightforward but tedious, so I am providing the following snippets of code for anyone else who may need to interface to this or similar serial-controlled LED 8-segment (7 for digit plus decimal) displays in the future. Simple modifications to the code can allow for variations in how the data is displayed. Hopefully this will help others who want to use their Arduino with these displays. The comments in the code explain how it works, but if there are any questions, let me know!


//variable definitions

int clockPin = 10;    //digital pin for the serial clock
int dataPin = 11;    //digital pin for the serial data
int resetPin = 12;    //digital pin for serial reset

int integerArray[4];  //integer array that will eventually be displayed on LED display

byte passArray[5];    //byte arrays for the shiftOut() function
byte failArray[5];
byte displayLEDArray[5];

byte LED0 = 0x7E;    //bytes corresponding to the number shapes on the LED display
byte LED0Dot = 0x7F;
byte LED1 = 0x0C;
byte LED1Dot = 0x0D;
byte LED2 = 0xB6;
byte LED2Dot = 0xB7;
byte LED3 = 0x9E;
byte LED3Dot = 0x9F;
byte LED4 = 0xCC;
byte LED4Dot = 0xCD;
byte LED5 = 0xDA;
byte LED5Dot = 0xDB;
byte LED6 = 0xFA;
byte LED6Dot = 0xFB;
byte LED7 = 0x0E;
byte LED7Dot = 0x0F;
byte LED8 = 0xFE;
byte LED8Dot = 0xFF;
byte LED9 = 0xCE;
byte LED9Dot = 0xCF;
byte LEDOff = 0x00;

void setup() {

  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(resetPin, OUTPUT);  
  
  //byte arrays loaded for PASS/FAIL LED display
        
  passArray[0] = 0x10; //00010000 - leading zeros, start bit, and external LED bits (off)
  passArray[1] = 0xDA; //11011010 - S (no decimal)
  passArray[2] = 0xDA; //11011010 - S (no decimal)
  passArray[3] = 0xEE; //11101110 - A (no decimal)
  passArray[4] = 0xE6; //11100110 - P (no decimal)
        
  failArray[0] = 0x10; //00010000 - leading zeros, start bit, and external LED bits (off)
  failArray[1] = 0x70; //01110000 - L (no decimal)
  failArray[2] = 0x60; //01100000 - I (no decimal)
  failArray[3] = 0xEE; //11101110 - A (no decimal)
  failArray[4] = 0xE2; //11100010 - F (no decimal)
  
  displayLEDArray[0] = 0x10;  //first byte in the LED display array loaded with leading zeros and start bit
}

void loop() {

  digitalWrite(resetPin, LOW);
  for (int j = 0; j < 5; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, failArray[j]);  //displays FAIL on LED display
  }

  digitalWrite(resetPin, LOW);
  for (int j = 0; j < 5; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, failArray[j]);  //displays PASS on LED display
  }

  fillArray();  //fills displayLEDArray with correct bytes to draw characters on LED display corresponding to integers in integerArray

  digitalWrite(resetPin, LOW);
  for (int j = 0; j < 5; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, displayLEDArray[j]);  //displays other numerical data as stored in the byte array with fillArray()
  }
}

void fillArray() {
  for (int i = 1; i < 5; i++) {  //we start at 1 because the first byte was already loaded up with leading zeros and the start bit
          switch (integerArray[(i-1)]) {
            case 0:  
              if (i == 2) {  //the third byte contains the decimal point, giving you 2 significant digits - change to i == 3 for 3 significant digits
                displayLEDArray[i] = LED0Dot;  
              } else
              if (i == 4) {
                displayLEDArray[i] = LEDOff;  //leading zero is not displayed (e.g. 03.14 displayed as 3.14, while 0.31 will display as is)
              } 
              else
                displayLEDArray[i] = LED0;
              break;
            case 1:
              if (i == 2) {
                displayLEDArray[i] = LED1Dot;
              } 
              else
                displayLEDArray[i] = LED1;
              break;
            case 2:
              if (i == 2) {
                displayLEDArray[i] = LED2Dot;
              } 
              else
                displayLEDArray[i] = LED2;
              break;
            case 3:
              if (i == 2) {
                displayLEDArray[i] = LED3Dot;
              } 
              else
                displayLEDArray[i] = LED3;
              break;
            case 4:
              if (i == 2) {
                displayLEDArray[i] = LED4Dot;
              } 
              else
                displayLEDArray[i] = LED4;
              break;
            case 5:
              if (i == 2) {
                displayLEDArray[i] = LED5Dot;
              } 
              else
                displayLEDArray[i] = LED5;
              break;
            case 6:
              if (i == 2) {
                displayLEDArray[i] = LED6Dot;
              } 
              else
                displayLEDArray[i] = LED6;
              break;
            case 7:
              if (i == 2) {
                displayLEDArray[i] = LED7Dot;
              } 
              else
                displayLEDArray[i] = LED7;
              break;
            case 8:
              if (i == 2) {
                displayLEDArray[i] = LED8Dot;
              } 
              else
                displayLEDArray[i] = LED8;
              break;
            case 9:
              if (i == 2) {
                displayLEDArray[i] = LED9Dot;
              } 
              else
                displayLEDArray[i] = LED9;
              break;
          }
     } 
}