I have a left-shifting 5-digit cc-type 7-segment display sub unit (Price Field of Fig-1) being driven by MAX7219 chips, which holds price of goods in the range: 00000 - 99999 (000.00 - 999.99). The cc-codes of the digits being shown on the display sub unit are available to me via byte type 5 variables. I would like to map these cc-codes (0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B for 0, 1, ..., 9) into ASCII codes (0x30, 0x31, ..., 0x39 for 0, 1, ..., 9) in order to use the atol() function to get the price in integer form which will be used to compute the cost of the goods. Currently, I have solved the issue using switch-case structure (display-circuit/codes are given below); alternative idea/algorithm is being longed to enrich my collection.
A: Schematic of the Display Unit
Figure-1: Display unit of a UNO-MAX7219 based Digital Weighing Machine (DWM)
B: Pictorial View of the Prototype Digital Weighing of which the Price Field is a Sub Unit
Figure-2: Pictorial view of the prototype DWM
C: Partial Codes for Price Entry, Weight Acquisition, Cost Computation, and Display Update.
byte lupTable[] = {0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47};
//0, 1, ...., E, F (p, a, b, c, d, e, f g)
byte ccCode[16] = {0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E};
//ccCode0-ccCode4(wt) ; ccCode5-ccCode9(price); ccCode10-ccCode15(cost)
char keyAscii[6] = "";
void loop()
{
byte customKey = customKeypad.getKey();
if (customKey)
{
i++;
ccKey = lupTable[(customKey & 0x0F)]; //cc-code is saved
//------------------------------------------------------
ccCode[5] = ccCode[6];
ccCode[6] = ccCode[7];
ccCode[7] = ccCode[8];
ccCode[8] = ccCode[9];
ccCode[9] = ccKey;
displayPrice();
//-----------------------------------------
zero = caseSwitch(ccCode[5]); // 0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70,0x7F, 0x7B
one = caseSwitch(ccCode[6]);
two = caseSwitch(ccCode[7]);
three = caseSwitch(ccCode[8]);
four = caseSwitch(ccCode[9]);
if (flag2 == LOW)
{
caseSwitchA(i);
}
else
{
caseSwitchA(5);
}
price = atol(keyAscii); //0.00 - 999.99
}
else
{
weight(); //returns tWt as integer
cost = tWt * price; //12375 * rate; //tWt * price; //as integer
binToBcdCost(); //updates ccCode[] Table
showDisplay();
}
}
//-------------------------------------------------
byte caseSwitch(byte x) //0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70,0x7F, 0x7B
{
switch (x)
{
case 0x7E: return 0x30;
case 0x30: return 0x31;
case 0x6D: return 0x32;
case 0x79: return 0x33;
case 0x33: return 0x34;
case 0x5B: return 0x35;
case 0x5F: return 0x36;
case 0x70: return 0x37;
case 0x7F: return 0x38;
case 0x7B: return 0x39;
}
}
//----------------------------------
byte caseSwitchA(byte x)
{
switch (x)
{
case 1:
{
keyAscii[0] = four;
keyAscii[1] = 0x00;//three;
keyAscii[2] = 0x00;//two
keyAscii[3] = 0x00;//one;
keyAscii[4] = 0x00;//zero;
}
break;
case 2:
{
keyAscii[0] = three;
keyAscii[1] = four;
keyAscii[2] = 0x00;//two;
keyAscii[3] = 0x00;//one;
keyAscii[4] = 0x00;//zero;
}
break;
case 3:
{
keyAscii[0] = two;
keyAscii[1] = three;
keyAscii[2] = four;
keyAscii[3] = 0x00;//one;
keyAscii[4] = 0x00;//zero;
}
break;
case 4:
{
keyAscii[0] = one;
keyAscii[1] = two;
keyAscii[2] = three;
keyAscii[3] = four;
keyAscii[4] = 0x00;//zero;
}
break;
case 5:
{
keyAscii[0] = zero;
keyAscii[1] = one;
keyAscii[2] = two;
keyAscii[3] = three;
keyAscii[4] = four;
flag2 = HIGH;
}
break;
}
}