Skip to main content
1 of 3
JS1
  • 28.6k
  • 3
  • 41
  • 83

###Use an array instead of functions###

Instead of using multiple functions, you can encode your digit segments into a single array. For example:

// Define this array at the top of your program.
static const boolean digitVals[10][8] = {
    // zero
    {   true,   //a
        true,   //b
        true,   //c
        true,   //d
        true,   //e
        true,   //f
        false,  //g
        false   //h
    },
    // one
    {   false,  //a
        true,   //b
        true,   //c
        false,  //d
        false,  //e
        false,  //f
        false,  //g
        false   //h
    },
    // etc ...
};

// Then when you want to use it, you can simply use memcpy.
void sendtodisplay(char number, int digi)
{
    int index = number - '0';

    memcpy(&onOff[digi][0], &digitVals[index][0], 8 * sizeof(boolean));
}
JS1
  • 28.6k
  • 3
  • 41
  • 83