Skip to main content
Commonmark migration
Source Link

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

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]));
}

###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]));
}

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]));
}
edited body
Source Link
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]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][0]onOff[digi], &digitVals[index][0]digitSegments[index], 8 * sizeof(booleanonOff[digi]));
}

###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));
}

###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]));
}
Source Link
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));
}