Code:
PROGMEM const int mphTable[] = {
0,100,90,80,75,60,
4,1,1,1,1,1,
5,1,1,1,1,1,
6,1,1,1,1,1,
7,1,1,1,1,3,
8,1,1,2,2,5,
9,1,1,3,4,7,
10,1,2,4,5,9,
11,2,4,5,7,9,
12,3,5,7,8,10,
13,4,6,8,9,12,
14,5,8,9,9,13,
15,7,9,10,10,14,
16,8,9,11,11,16,
17,9,10,12,12,17,
18,9,11,13,13,18
};
PROGMEM const char *toplineTABLE[]={
"error",
" ",
"BATTERY",
"AUTO",
"MODE",
"ADJUST FRONT",
"ADJUST BACK",
"ADJUST AUTO",
"MOVE TO MID GR2",
"SETTINGS"
};
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
gearfromMphTable(12,2);
}
int gearfromMphTable(int thespeed, int rpmoffset){
int thegear;
thegear=pgm_read_word_near(mphTable+(thespeed-3)*6+rpmoffset); //for table with rpms in first row, starting with 4mph in second
return thegear;
}
RESULT: