Go Down

Topic: Display on ST 53L0A1 board (Read 27 times) previous topic - next topic

AmphenolSensors


After searching high and low for a library to write to the display on this shield I wrote the enclosed. Not particularly tidy, the display only accepts integers (no decimal point enabled on the board), perhaps someone with more knowledge can make it into a library, but it does work and may help others

Code: [Select]

#include "Wire.h"

void setup()
{
  Serial.begin(19200);
  Serial.println(__FILE__);
  pinMode(12, OUTPUT); //chip select on 53L0A1 board
  digitalWrite(12, HIGH);

  Wire.begin();
  Wire.setClock(100000);

  clearDisplay();
  beginDisplay();
  clearDisplay();
}

int i = 0;

void loop()
{
  //display(i);
  i++;
  //delay(200);
testDisplay();
}

static const byte charmap[] = {
  B00000100,   // 0  within map, 0 is LED ON
  B00011111,   // 1
  B01000010,   // 2
  B00000011,   // 3
  B00011001,   // 4
  B00100001,   // 5
  B00101000,   // 6
  B00010111,   // 7
  B00000000,   // 8
  B00010001,   // 9
  B11111111,   // space 10
};

void display(int aa) {
  byte Digit[4];
  byte Segment[4];

  Segment[0] = charmap[10];
  Segment[1] = charmap[10];
  Segment[2] = charmap[10];
  Segment[3] = charmap[10];

  Digit[0] = (aa / 1000) % 10;  // thousands
  Digit[1] = (aa / 100) % 10;   // hundreds
  Digit[2] = (aa / 10) % 10;    // tens
  Digit[3] = aa % 10;           // ones

  if (Digit[0] != 0) {
    Segment[0] = charmap[Digit[0]];
    Segment[1] = charmap[0];
    Segment[2] = charmap[0];
    Segment[3] = charmap[0];
  }
  if (Digit[1] != 0) {
    Segment[1] = charmap[Digit[1]];
    Segment[2] = charmap[0];
    Segment[3] = charmap[0];
  }

  if (Digit[2] != 0) {
    Segment[2] = charmap[Digit[2]];
    Segment[3] = charmap[0];
  }
  if (Digit[3] != 0) {
    Segment[3] = charmap[Digit[3]];
  }

  Segment[0] = bitWrite(Segment[0], 7, bitRead(Segment[1], 0)) ;
  Segment[1] = Segment[1] >> 1;

  Segment[2] = bitWrite(Segment[2], 7, bitRead(Segment[3], 0)) ;
  Segment[3] = Segment[3] >> 1;

  sendValue(0x43, 0x12, Segment[0]);  //1st Segment
  sendValue(0x43, 0x13, Segment[1]);  //2nd Segment
  sendValue(0x42, 0x12, Segment[2]);  //3rd Segment 
  sendValue(0x42, 0x13, Segment[3]);  //4th Segment
}

void clearDisplay() {
  sendValue(0x43, 0x12, B11111111);  //1st Segment
  sendValue(0x43, 0x13, B11111111);  //2nd Segment
  sendValue(0x42, 0x12, B11111111);  //3rd Segment 
  sendValue(0x42, 0x13, B11111111);  //4th Segment
}

void beginDisplay() {
  sendValue(0x42, 0x14, B11111111); //set each segment as output
  sendValue(0x42, 0x15, B11111111);
  sendValue(0x43, 0x14, B11111111);
  sendValue(0x43, 0x15, B11111111);

  sendValue(0x43, 0x12, B11111011);  //send a minus sign
  delay(500);
  sendValue(0x43, 0x13, B11111101);
  delay(500);
  sendValue(0x42, 0x12, B11111011);
  delay(500);
  sendValue(0x42, 0x13, B11111101);
  delay(500);
}

void testDisplay() {
  sendValue(0x43, 0x12, B11111111);  //1st Segment
  sendValue(0x43, 0x13, B11111111);  //2nd Segment
  sendValue(0x42, 0x12, B11111111);  //3rd Segment 
  sendValue(0x42, 0x13, B11111111);  //4th Segment

  sendValue(0x43, 0x12, B11111011);delay(250);  //1st Segment
  sendValue(0x43, 0x12, B10111111);delay(250);
  sendValue(0x43, 0x12, B11110111);delay(250);
  sendValue(0x43, 0x12, B11111101);delay(250);
  sendValue(0x43, 0x12, B11111110);delay(250);
  sendValue(0x43, 0x12, B11101111);delay(250);
  sendValue(0x43, 0x12, B10111111);delay(250);
  sendValue(0x43, 0x12, B11111111);delay(250);

  sendValue(0x43, 0x13, B11111101);delay(250);  //2nd Segment
  sendValue(0x43, 0x13, B11101111);delay(250);
  sendValue(0x43, 0x13, B11111011);delay(250);
  sendValue(0x43, 0x12, B01111111);
  sendValue(0x43, 0x13, B11111111);delay(250);
  sendValue(0x43, 0x12, B11111111);
  sendValue(0x43, 0x13, B11110111);delay(250);
  sendValue(0x43, 0x13, B11011111);delay(250);
  sendValue(0x43, 0x13, B11111111);delay(250);

  sendValue(0x42, 0x12, B11111011);delay(250);  //3rd Segment
  sendValue(0x42, 0x12, B11011111);delay(250);
  sendValue(0x42, 0x12, B11110111);delay(250);
  sendValue(0x42, 0x12, B11111101);delay(250);
  sendValue(0x42, 0x12, B11111110);delay(250);
  sendValue(0x42, 0x12, B11101111);delay(250);
  sendValue(0x42, 0x12, B10111111);delay(250);
  sendValue(0x42, 0x12, B11111111);delay(250);

  sendValue(0x42, 0x13, B11111101);delay(250);  //4th Segment
  sendValue(0x42, 0x13, B11101111);delay(250);
  sendValue(0x42, 0x13, B11111011);delay(250);
  sendValue(0x42, 0x12, B01111111);
  sendValue(0x42, 0x13, B11111111);delay(250);
  sendValue(0x42, 0x12, B11111111);
  sendValue(0x42, 0x13, B11110111);delay(250);
  sendValue(0x42, 0x13, B11011111);delay(250);
  sendValue(0x42, 0x13, B11111111);delay(250);
}

void sendValue(byte aa, byte bb, byte cc) { //address, register, value
  Wire.beginTransmission(aa);
  Wire.write(bb);
  Wire.write(cc);
  Wire.endTransmission();
}

Go Up