Just a note since other people are doing the same sort of thing as the position switch, to minimize the possibility of fudgy readings, using the midpoint between readings is useful:
readings sorted by value and midpoints:
Code:
n 643
635
2 627
605
p 584
550
r 515
441
3 368
346
d 323
207
4 91
so a function like this should be fairly reliable and allow for a bit of switch/connection degradation:
Code:
//map the position switch resistor reading to an actual position
int position(val){
if(val > 700)
return ERROR;
if(val > 635)
return NEUTRAL;
if(val > 605)
return SECOND;
if(val > 550)
return PARK;
if(val > 441)
return REVERSE;
if(val > 346)
return THIRD;
if(val > 207)
return DRIVE;
return FOURTH;
}