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)