Read Seven Segment VFD Multiplexing Display With Array/Lookup Table or Hashmap?

Background:
I'm working on a project where I intend to read the weight of an analytical lab balance by direct reading the Vacuum Florescent Display (VFD).

Currently I'm trying to figure out how to decode the info I get from the multiplexing display. I'm not terribly familiar with Arrays/Lookup Tables, Associative Arrays or Hashmaps (to my understanding Hashmaps aren't even available on the Arduino platform), and I haven't been able to find clear information on this matter.

Essentially this is what I'm trying to accomplish:

1 - Read my 8 segment input pins and concatenate them into a string.
2 - Decode that String with an Array/Lookup Table.
3 - Print that string to a 16X2 LCD.
4 - [Eventually] Control a stepper motor based on the current weight.

Currently, I'm hung up on how to decode the input.

Please see attached table (image) depicting my values.

Table: http://imgur.com/JuczQOO

NOTES:

  1. The eighth segment --Pin 11-- is a decimal point on the display.
  2. The "Pins" are the pins on the VFD.

My Test Code in Circuit I/O:

#include <LiquidCrystal.h>

long StartMillis = 3000; //Duration for Boot screen.
long CurrentMillis = 0; //Current Time on Clock.

String Weight = ""; //Starting Weight Should be nil.
String Startup = "Startup Text!"; //Startup Text.
String CatStr = "empty"; //Concatenation of inputs 
String STRA = "0";// In the future these will become defined input pins as opposed to strings.
String STRB = "1";// In the future these will become defined input pins as opposed to strings.
String STRC = "2";// In the future these will become defined input pins as opposed to strings.
String STRD = "3";// In the future these will become defined input pins as opposed to strings.
String STRE = "4";// In the future these will become defined input pins as opposed to strings.
String STRF = "5";// In the future these will become defined input pins as opposed to strings.
String STRG = "6";// In the future these will become defined input pins as opposed to strings.
String STRH = "7";// In the future these will become defined input pins as opposed to strings.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//Lookup Table:
/*
T B
0,11101110
1,00100100
2,10111010
3,10110110
4,01110100
5,11010110
6,11011110
7,10100100
8,11111110
9,00000000
*/
//End Lookup Table

void setup()
{
 
  lcd.begin(16, 2);
  lcd.clear();
}

void loop()
{
  unsigned long CurrentMillis = millis ();
  String CatStr = "";
  CatStr = (STRA)+(STRB)+(STRC)+(STRD)+(STRE)+(STRF)+(STRG)+(STRH);
  //Weight = CatStr [decoded]
  if (CurrentMillis < StartMillis)
  {
    lcd.print(Startup);
    delay(2000);
    lcd.clear();
  }
  else
  {
    lcd.print(CatStr); //later, this will be "Weight" not "CatStr."
    delay(3000);
    lcd.clear();
    lcd.print("Yay!");
    delay(1000);
    lcd.clear();
  }
}

Thanks in advance for all the help!

First thing you need to do is ditch the String class. Then look a good seven segment display library to see how things are done, and just reverse the process.

aarg:
First thing you need to do is ditch the String class. Then look a good seven segment display library to see how things are done, and just reverse the process.

  1. Understandable on ditching the strings.
  2. I've read up on VFDs and Multiplexing, but doing the "reverse" is where i'm hitting a small snag. I'm not sure how to go about decoding the 7 segments that are being read...

I feel as though something 'like' an Array would be the best approach, but I haven't yet figured out exactly how I should do this.

Thanks for the wisdom on the Strings!

Did you look at any seven segment libraries? Typically the segment mappings are efficiently stored in a byte array like this:

  const byte SEVEN_SEGMENT[] = {
    0b00111111, // 0
    0b00000110, // 1
    0b01011011, // 2
    0b01001111, // 3
    0b01100110, // 4
    0b01101101, // 5
    0b01111101, // 6
    0b00000111, // 7
    0b01111111, // 8
    0b01101111, // 9
  };

In this table the segments are stored like GFEDCBA.

aarg:
Did you look at any seven segment libraries? Typically the segment mappings are efficiently stored in a byte array like this:

  const byte SEVEN_SEGMENT[] = {

0b00111111, // 0
    0b00000110, // 1
    0b01011011, // 2
    0b01001111, // 3
    0b01100110, // 4
    0b01101101, // 5
    0b01111101, // 6
    0b00000111, // 7
    0b01111111, // 8
    0b01101111, // 9
  };




In this table the segments are stored like <dp>GFEDCBA.

I'm sorry, I guess I hadn't looked at Arduino Libraries. Looking now! Will post updated Code when it's functioning.

Thanks, aarg!

Here's what I came up with.

  1. I used an Array to store my 10 number possibilities for each character on the display (e.g., 0-9).
  2. I then incrementally checked my input values, that were concatenated together, against each strings in the Array until there was a match.
  3. Upon a match, I set my variable to be printed to the LCD as the number of the string in the Array. The Array is organized appropriately so the number zero (0) is the first (0th) and the number nine (9) is the last (9th) string in the Array.

Note, I have not updated this to utilize int instead of String yet.

I'm sure there is probably a more efficient way to accomplish this as opposed to cycling through my Array until there is a match, but this is what I was able to come up with.

Anyways, I Hope this is useful to someone in the future.

#include <LiquidCrystal.h>

long StartMillis = 500; //Duration for Boot screen.
long CurrentMillis = 0; //Current Time on Clock.

String NumArray[] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111010"};//Array Used for decoding.
String InVal = "0";//represents the 10 values in the Array.
String CatStr = ""; //Concatenation of inputs 
String STRA = "1";//
String STRB = "1";//
String STRC = "1";//These represent the soon to be input pins of the VFD. 
String STRD = "1";//Currently, this represents the VFD Segment state for the number nine (9).
String STRE = "0";//
String STRF = "1";//
String STRG = "0";//
//String STRH = "0";// This is the Decimal Pin.

int Num = 99;//Number value of decoded inputs. (starts at 99 for the purpose of while loop).
int val = 0;//Used in while loop, incremented by +1 each time the while loop cycles.

//Array Decoding Table
//  1110111, = 0
//  0010010, = 1
//  1011101, = 2
//  1011011, = 3
//  0111010, = 4
//  1101011, = 5
//  1101111, = 6
//  1010010, = 7
//  1111111, = 8
//  1111010, = 9
//Array Decoding Table

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//Define LCD pins.

void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
}

void loop()
{
  unsigned long CurrentMillis = millis ();

  CatStr = (STRA) + (STRB) + (STRC) + (STRD) + (STRE) + (STRF) + (STRG);//Concatenate the input pins into a single string.
  val = 0;//set starting search position for Array.
  InVal = NumArray[val];//Sets starting value of Array search (value for "zero" (0)).

  if (CurrentMillis < StartMillis)//Startup message
  {
    lcd.setCursor (0,0);
    lcd.print("Startup Text!");
    lcd.setCursor (0,1);
    lcd.print ("Welcome!");
    delay(500);
    lcd.clear();
  }
  else
  {
    while (Num > 9)//while Loop to search for input string matches with Array values.
    {
      if (CatStr == InVal)//Check whether input pins match with current array value.
      {
        Num = val;//if a match is found, set "num" value to the Array string number that returned true.
      }
      else
      {
        val = val + 1;//incriment Val by +1
        InVal = NumArray[val];//Set to next string in array
        if (val > Num)//prevents an eternal loop in the event of an error (used for code development.
        {
          Num = -99;
        }
      }
    }
    lcd.setCursor (0,0);
    lcd.print (Num);
    lcd.setCursor (0,1);
    lcd.print (CatStr);
    delay(2000);
    lcd.clear();
    lcd.print("Yay!");
    delay(500);
    lcd.clear();
  }
}

Your table search logic is very confusing. A conventional approach would be more like:

code = -1 // a value understood to mean "not found"

for ( index = 0, index < tablesize, index++)
{
if (table[index] == candidate)
{
code = index
}
}

If the data is stored in bytes, this algorithm will take about 0.5 to 5 microseconds to complete. You don't need any hash tables or binary search algorithms for such a simple job.