Project Gear indicator.

First of all, to say that I am quite new and so I am quite lost in the language of Arduino.
I am immersed in my personal project which is to create a gearshift indicator to connect it to a steering wheel of PS4.
Look on the internet, I got a code and I modified it to make the gears, neutral and reverse. So far so good.

As I use it with different cars, some have a maximum of 4 gears, another 5, and so on. I would like to select the maximum number of marches to display using a dial that activates the different Arduino ports. For example: if pin 11 reads HIGH, limit the number of gears to 4, if pin 12 reads HIGH, the number of gears is 5, and so on.

I´ve tried some instructions, I couldn´t get it working.

The code I´m using is:

#define BUTTON_DOWN 9
#define BUTTON_UP 10


int ledPinA =  2;    // LED connected to digital pin 3
int ledPinB =  3;    // LED connected to digital pin 4
int ledPinC =  4;    // LED connected to digital pin 5
int ledPinD =  5;    // LED connected to digital pin 6
int ledPinE =  6;    // LED connected to digital pin 7
int ledPinF =  7;    // LED connected to digital pin 8
int ledPinG =  8;    // LED connected to digital pin 9

int val_down = 0;
int old_val_down = 0;

int val_up = 0;
int old_val_up = 0;
int state = 0;
int gear = 1;

void setup() 

  {             
  pinMode(BUTTON_DOWN, INPUT_PULLUP);
  pinMode(BUTTON_UP, INPUT_PULLUP);

  
  

  pinMode(ledPinA, OUTPUT);
  pinMode(ledPinB, OUTPUT);
  pinMode(ledPinC, OUTPUT);
  pinMode(ledPinD, OUTPUT);
  pinMode(ledPinE, OUTPUT);
  pinMode(ledPinF, OUTPUT);
  pinMode(ledPinG, OUTPUT);  

  
  
}

void led0()// r 
           
{
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, HIGH);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, HIGH); 
           
}

void led1()// n 
{
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, HIGH);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, HIGH);
          
}

void led2()//1
{
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, LOW); 
 
}

void led3()//2
{
  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, HIGH); 
     
}

void led4()//3
{
  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, LOW);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, HIGH); 
  
 } 

void led5()//4
{
 digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);  
  digitalWrite(ledPinF, HIGH);  
  digitalWrite(ledPinG, HIGH); 
 
 } 

void led6()//5
{
  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, LOW);  
  digitalWrite(ledPinF, HIGH);  
  digitalWrite(ledPinG, HIGH); 
   
 } 

void led7()//6
{
  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);  
  digitalWrite(ledPinF, HIGH);  
  digitalWrite(ledPinG, HIGH); 
} 

void led8()//7
{
digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, LOW);  

} 

void led9()
{
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, HIGH);  
  digitalWrite(ledPinF, LOW);  
  digitalWrite(ledPinG, LOW); 
 
} 

void setLed(int number)
{
  switch (number) {
      case 0:  
      led0();
      break;
      
   case 1:  
      led1();
      break;
    case 2:  
      led2();
      break;
    case 3:  
      led3();
      break;
    case 4:  
      led4();
      break;
    case 5:  
      led5();
      break;
    case 6:  
      led6();
      break;
    case 7:  
      led7();
      break;
    case 8:  
      led8();
      break;
    case 9:  
      led9();
      break;
  }
}
              

void oldloop()                     
{
                    // wait for a second
  led0();
  delay(1000);                  // wait for a second
  led1();
  delay(1000);                  // wait for a second
  led2();
  delay(1000);                  // wait for a second
  led3();
  delay(1000);                  // wait for a second
  led4();
  delay(1000);                  // wait for a second
  led5();
  delay(1000);                  // wait for a second
  led6();
  delay(1000);                  // wait for a second
  led7();
  delay(1000);                  // wait for a second
  led8();
  delay(1000);                  // wait for a second
  led9();
  delay(1000);                  // wait for a second
}

void loop()
{ 
    val_up = digitalRead(BUTTON_UP);
    if ((val_up == HIGH) && (old_val_up == LOW)&&gear<8 ) 
    {
      gear += 1;
     
      delay(250);
    }
    
    old_val_up = val_up;
 
    val_down = digitalRead(BUTTON_DOWN);
    
    if ((val_down == HIGH) && (old_val_down == LOW)&&gear>1 )
    { 
      gear -= 1;
   
      delay(250);
    } 
    
  else   if ((val_down == HIGH) && (old_val_down == LOW)&&(gear<1))

{ 
      gear += 1;
    
      delay(250);
    }
    
   
   else   if ((val_down == HIGH) && (old_val_down == LOW))
   { 
      gear += -1;
    
      delay(250);
    }
       
    old_val_down = val_down;
   

  
   
   
    setLed(gear);
}

Thanks in advance!

Was there a question?
Can we expect code tags?

I´m trying to write the code so that allows to select the maximum gears to display. E.g: if the car only has 5 gears, the maximum number showed on the display is 5.

I found out that if I modify “gear<8” to “gear<6” on the line below, the displays only allows me to select up to 5th gear.

val_up = digitalRead(BUTTON_UP);
if ((val_up == HIGH) && (old_val_up == LOW)&&gear<8 )

My aim is to connect like a rotary switch to select the maximum gears to be displayed.

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Ok, I´ve edit my original post now in order to read easly the code.

I think my target should be play with the variable “gear”. I´ve added the line below to the loop, but the only change I´ve made is stuck the display :(.

Any thoughts out there?

int gear = digitalRead(SELECTOR);
   if (SELECTOR == HIGH)
   {
    gear = gear<7;
}

[\CODE]

gmoreno84gm:

    gear = gear<7;

That’s going to compare the variable gear to the number 7 and return true if it is less than 7. Then it assigns that result to gear. What gear is TRUE going to represent?

Have you picked out a rotary switch yet? Do you have enough spare digital inputs to connect all the switch wires to the Arduino? Try to make another simple sketch which just prints out to the serial monitor which position the switch is in. Then we can work together on getting that information into the original sketch.

thanks for your answer MorganS.

I was on the wrong path then... :(. The only thing I´m trying so far, is limit the number showed in the segment display when pin 11 is HIGH. To do this, I´m just using an on/off switch. So, the idea is:

If pin 11 is HIGH, the maximum number to show in the display is "5". Any ideas about how can I do this bit?

If I succeed with this project, I will jump to use the rotary switch but at that stage, I will need to drive the display through a shift register as I´m running out of digital ports.

Thanks.

  if(digitalRead(11)) maxGear=5;

You are missing some detail in your specification. What should the max be when it’s LOW?

Pick a switch first. Most rotary switches can be connected to a few resistors to make an analog voltage suitable for an analog input, so you only need to use one pin for a multi-position switch.