As promised the Arduino code for the project (below). The switched 12v and GND supply was taken from the diagnostic connector. The connection to the gear position sensor was soldered into the wiring loom by stripping back a very small section of insulation and tacking on a wire. Photos of the installed unit to follow. -
// 7 segment LED pin connections
//
// --3--
// 7 4
// --2--
// 9 6
// --8--
// 5
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
int I;
for (I=0;I<5;I++)
{
circle();
}
int ReadVal;
for (;;) // Infinite loop
{
// Average from 20 readings to remove any noise issues
ReadVal=0;
for (I=0;I<20;I++)
{
ReadVal=ReadVal+analogRead(A0);
}
ReadVal=ReadVal/20;
// Display appropriate digit
if (ReadVal<329) // 1.39V <1.61V
{
one();
}
else if (ReadVal>=329 && ReadVal<448) // 1.82V >1.61V <2.19V
{
two();
}
else if (ReadVal>=448 && ReadVal<591) // 2.55V >2.19V <2.89V
{
three();
}
else if (ReadVal>=591 && ReadVal<747) // 3.22V >2.89V <3.65V
{
four();
}
else if (ReadVal>=747 && ReadVal<878) // 4.07V >3.65V <4.29V
{
five();
}
else if (ReadVal>=878 && ReadVal<968) // 4.51V >4.29V <4.73V
{
six();
}
else if (ReadVal>=968) // 4.95V >4.73V
{
zero();
}
}
}
void circle(){
digitalWrite(3, HIGH);
delay(100);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
digitalWrite(6, HIGH);
delay(100);
digitalWrite(6, LOW);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(100);
digitalWrite(9, LOW);
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
}
void DP_On(){
digitalWrite(5, HIGH);
}
void DP_Off(){
digitalWrite(5, LOW);
}
void blank(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void zero(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
void one(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void two(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
void three(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
}
void four(){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void five(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
}
void six(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
void eight(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}