GEAR INDICATOR FOR RACING CAR

hello to all,today i creat a gear indicator for a racing car ,with seven segment,shifter 74hc595 kai a multiple switch ,everything is working fine but i want to make it work with a pontesiometer,beacause it has 6 gears and i dont want to put 6 switches,can any one help me??(i have attc the photo from the old sensor,thet the car has)
the potentiometer i have is 1K, the code is

int latchPin = 2;
int dataPin =3;
int clockPin =4;
const int buttonPin = 6; // the number of the pushbutton pin
const int button2Pin = 9; // the number of the pushbutton pin
const int button3Pin = 7;
const int button4Pin = 8;
const int button5Pin = 11;
const int button6Pin = 10;
// the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int button2State = 0;
int button3State = 0;
int button4State = 0;
int button5State = 0;
int button6State = 0;

void setup(){
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
pinMode(button5Pin, INPUT);
pinMode(button6Pin, INPUT);
}

void loop(){
buttonState = digitalRead(buttonPin);
button2State = digitalRead(button2Pin);
button3State = digitalRead(button3Pin);
button4State = digitalRead(button4Pin);
button5State = digitalRead(button5Pin);
button6State = digitalRead(button6Pin);
//0

if (buttonState == LOW)
if (button2State == LOW)
if (button3State == LOW)
if (button4State == LOW)
if (button5State == LOW)
if (button6State == LOW){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 43);
digitalWrite(latchPin,HIGH);

}

//1

if (button2State == LOW)
if (button3State == LOW)
if (button4State == LOW)
if (buttonState == HIGH)
if (button5State == LOW)
if (button6State == LOW){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 121);
digitalWrite(latchPin,HIGH);
}
//2

if (button3State == LOW)
if (button2State == HIGH)
if (button4State == LOW)
if (buttonState == LOW)
if (button5State == LOW)
if (button6State == LOW){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 36);
digitalWrite(latchPin,HIGH);

}
//3

if (button4State == LOW)
if (button2State == LOW)
if (button3State == HIGH)
if (buttonState == LOW)
if (button5State == LOW)
if (button6State == LOW){
digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 48);
digitalWrite(latchPin,HIGH);
}
//4

if (buttonState == LOW)
if (button2State == LOW)
if (button3State == LOW)
if (button4State == HIGH)
if (button5State == LOW)
if (button6State == LOW){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 25);
digitalWrite(latchPin,HIGH);

}
//5

if (buttonState == LOW)
if (button2State == LOW)
if (button3State == LOW)
if (button4State == LOW)
if (button5State == HIGH)
if (button6State == LOW){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 18);
digitalWrite(latchPin,HIGH);
}
//6

if (buttonState == LOW)
if (button2State == LOW)
if (button3State == LOW)
if (button4State == LOW)
if (button5State == LOW)
if (button6State == HIGH){

digitalWrite(latchPin,LOW);
shiftOut(dataPin,clockPin,MSBFIRST, 2);
digitalWrite(latchPin,HIGH);

}
}

gear_test_1_.ino (2.9 KB)

You would save yourself a lot of typing (and scope for errors) if you learn about arrays

If I understand correctly, you want to use a potentiometer in such a way that the position of the potentiometer indicates what gear has been selected.

When you use analogRead() to detect the position of the pot it will give a value between 0 and 1023. You just need to decide what values are appropriate to what gear position. Then you could have code something like this

potVal = analogRead(potPin);
if (potVal > 850) {
   // first gear
}
else if (potVal > 650) {
   // second gear
}
// etc

If you are talking about a real racing car with a lot of heat and vibration I wonder if a potentiometer would be reliable.

What is the problem with using 6 switches?
And I guess you could get away with 5 switches if one gear position is reprented by no switch being pressed.

...R

thank you for reply,yes its a real racing car and i have found o pot with 2 values 0-1023 and 1023 to 0 at the same time,its like throtle position sensor,the problem is the transmission has a small hall and from the neutral to 6 gear it turn about 45 degrees and the switch i have found, to work all the gears, must turn 90 degrees thats why..well the gears with R,N 1-6 needs 8 switches..any way thank you and when i finish it i post it...

to use that pot what you need are levers the right length's.

it can be mathed out but I don't know the formula(maybe someone here knows).
I just lay it out as in the picture.

if the trans is 45 deg. and you chose a 1.25 inch lever(you may be able to just drill a hole on the existing lever)
then a 3/4 inch lever on the pot will get you what you need.

the diagram should be self explanitory but if you need just ask.

Hutkikz:
to use that pot what you need are levers the right length's.

it can be mathed out but I don't know the formula(maybe someone here knows).
I just lay it out as in the picture.

if the trans is 45 deg. and you chose a 1.25 inch lever(you may be able to just drill a hole on the existing lever)
then a 3/4 inch lever on the pot will get you what you need.

the diagram should be self explanitory but if you need just ask.

thanks for your reply,well first of all this car it doesnt have shift lever like a normal car because is sequential,and the sensor if you see the picture i have att to the previous post,you see that the sensor fits to a small hall to the transmission shell,and when you do upshifts or downshifts it turns a small rotor inside who turns the sensor,this rotor from N TO 6 gear makes 45 degrees turn,so i found a double pot for safety and i have done it(can i post it here??)

this is the transmission

st82.jpg

No, this is transmission Joy Division - Transmission [OFFICIAL MUSIC VIDEO] - YouTube

AWOL:
No, this is transmission https://youtu.be/6dBt3mJtgJc

nice!!

Well if you have managed to connect the pot.
You can map the range of values you are getting from it to the eight positions you need
And it will function just fine even if you are not using the entire range of the pot.

Ian Curtis RIP

Hutkikz:
Well if you have managed to connect the pot.
You can map the range of values you are getting from it to the eight positions you need
And it will function just fine even if you are not using the entire range of the pot.

Ian Curtis RIP

thats right!