How do I write this IF statement?

What type is var2?

It sounds like you are planning to write a separate function to write each digit value (10) to each digit position (4), hence 40 functions. Don't do it that way

Suppose that you wrote a function to which you passed the digit position (0 - 3) and the digit to be displayed (0 - 9) then you could do it with a single function

You can split an int into separate digits like this

    //split the count into single digita
    data[0] = count / 1000;
    data[1] = (count / 100) % 10;
    data[2] = (count / 10) % 10;
    data[3] = count % 10;

declare an index of an array of segments for that digit value like this

const byte segmentData[] =
{
  0b11111100, //0
  0b01100000, //1
  0b11011010, //2
  0b11110010, //3
  0b01100110, //4
  0b10110110, //5
  0b10111110, //6
  0b11100000, //7
  0b11111110, //8
  0b11110110  //9
};

Iterate through the data array to get each digit value then use it to look up the associated segments and turn them on

haha yes that was exactly the plan. I understand what you are telling me but I'm not there yet in my arduino lingo but I'm looking into it now. As soon as johnwasser provided a solution I opened a new can of worms just organizing the whole mess.. this topic was more about finding a solution to the current road block.

Perhaps you can elaborate on your reply.. How do I implement your code?

Regards,

I am not sure that I can add more without actually writing the code, which I think you should do

Start by writing a sketch that splits the 4 digit number into separate digits and prints them on separate lines in the Serial monitor

Once that works write a function that takes a byte of value 0 to 9 and prints the corresponding entry in the segmentData array in binary. Call that from your first sketch. You should see a 1 for each segment that needs to be on and 0 for the others.

Using the bitRead() function you can iterate through the bits and turn the associated segments on or off

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