
typedef struct {
    unsigned char	*pValue;		// Pointer to scaled value
    unsigned 		loLimit;		// Low limit
    unsigned		hiLimit;		// High limit
    } CTableEntry;

unsigned char L, M, N, O;			// The scaled variables

CTableEntry table[] = {				// Table that correlates each
    { &L, 10, 35 },				//  of the scaled variables
    { &M, 30, 45 },				//  with its particular set of
    { &N, 60, 80 },				//  limits
    { &O, 25, 40 }
    };

#define TABLE_SIZE (sizeof(table) / sizeof(CTableEntry))

/* Some abbreviations that will make the code in DoScaling() easier to read */

#define VALUE		*table[j].pValue
#define RANGE		(table[j].hiLimit - table[j].loLimit)
#define OFFSET		table[j].loLimit
#define POT_RANGE	255

void DoScaling (				// Sets the scaled variables to
    unsigned char potValue			//  match this pot setting
    ) {

    int j;					// Table index

    for (j=0; j<TABLE_SIZE; j++) {		// For each table entry
        VALUE = OFFSET + (((RANGE * potValue)	// Calculate the corresponding
            + (POT_RANGE / 2)) / POT_RANGE);	//  scaled variable
	}					// End 'for each table entry'
    }						// End DoScaling()

/* Test program to make sure everything abovve this point works right */

void Dump(pot) {
    printf("Pot: %3d, L: %2d, M: %2d, N: %2d, O: %2d\n", pot, L, M, N, O);
    }

void main() {
    DoScaling(  0);  Dump(  0);
    DoScaling( 64);  Dump( 64);
    DoScaling(128);  Dump(128);
    DoScaling(192);  Dump(192);
    DoScaling(255);  Dump(255);
    }