Skip to main content
2 of 3
edited body
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 digitSegments[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], digitSegments[index], sizeof(onOff[digi]));
}
JS1
  • 28.6k
  • 3
  • 41
  • 83