Problem with getting right data from lookup table

Hello everyone,
I have a amall project which take some float values and display them on 7 segment . Using multiplexing segment on serial line. when I run simple loop and get char from my array of segment dat its ok but when I try to get segment data from same array with other char variable it didnot get correct data. I am stuck with getting right data from my char array for 7 segment here is snp of my code please point out problem.
`void getDigitsFromFloat(float number)
{
//char digits[10];
char digit;
char numberStr[8];
dtostrf(number,6, 2, numberStr);
Serial.print("converotF: ");
Serial.println(numberStr);
for (char i=0;i<8;i++ )
{
if (isdigit(numberStr[i]))
digNumber[i] = (char)numberStr[i];
//else
// digit = (digit || 0b00001000);// add decimal point with last digits

    //digNumber[i]  = digit;
}

//digNumber = digits;

}
void print7seg(float cost)
{
getDigitsFromFloat(cost);
char lop=0;
for(char i = 0;i<4;i++)
{
lop = (char)digNumber[i];
shiftData(numTable[lop]); //shif data byte to serial for t segment
// Serial.print("lop: ");
//Serial.println(lop);
// Serial.print("TableNum: ");
//Serial.println(numTable[lop]); //in serial monitor its shows correct lop no but it did not take right no from numTable array??
}

//for(int i =0;i<13;i++)
shiftData(0);
//Latch the data

digitalWrite(Latch,LOW);
delay(5);
digitalWrite(Latch,HIGH);
}
`
Here is my serial monitor display please guide whats wrong with this code

Welcome to the forum

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Back at you. Welcome to the forum.

It will be clearer when you post the code as @UKHeliBob suggests.

digNumber[i] = (char)numberStr[i];

may not be doing anything useful. I think I can discern confusion between a character like '1' and a number like 1.

Characters for printing are dealt with by their ASCII code . The code for '1' is not 1.

To get the number from a character constant, you can subtract the code for '0'. Fortunately the digit characters are in order, so it works.

Maybe

lop = digNumber[i] - '0';

but like I say, hard to be sure.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.