Paddle Shifter for automatic volvo with 7 segment display (almost done)

Hi people, i'm a Portuguese newbie

i've been programming a paddle shifter for my volvo 850 T5 automatic gearbox

It will allow me to do some things, some of the code is mine and some i took from the INTERNET i will explain and post my code.

1- switch will allow me to change from the original gearbox ecu to mine.

3-when running on ''auto mode'' my ''TCU'' (transmission control unit) will allow me to monitor the gear that the original TCU is driving and will show on the 7 segment display (tested and working).

3- I have a switch that when i press cuts the original TCU and puts mine in control, i have 2 switches near the stearing will that let me go UP and DOWN on gears my TCU controls 3 solenoids on the gearbox that allows me to change gears when activated in the correct sequence

4- every time i change gear the 7 segment display will show me the gear that i had selected

Till here is everything tested and working good

But now i only can change from auto to manual paddle shifting with the car stop because every time i change from auto to ''manual'' the initial gear is set to 1st

What i wanna do, and thats here that i need some help is add code to copy the last gear selected by the original TCU so when i change the switch from ''auto'' to ''manual'' my TCU assumes the last gear and i'm able to keep driving without stopping.

Remember that i'm monitoring the gears from the original TCU.

int gear = 1;
// output pins for transistor/relays controlled solenoids
int solA = 4;
int solB = 5;
int solC = 1;
// input pins for up down /  with pullup resistors
int gearup = 2;
int geardown = 3;
int sol1 = 14; //from the original TCU-read
int sol2 = 15; //from the original TCU-read
int sol3 = 16; //from the original TCU-read
int man = 17; // switch that change from auto to manual paddle shift
int val = 0; //val to read pin 14
int val2 = 0; //val to read pin 15
int val3 = 0; //val to read pin 16
int val4 = 0; //val to read the switch that change from auto to manual
//for 7 segment display
int b=7, a=6, e=10, d=9, f=11, c=8, g=12;

void setup() {
  pinMode(solA, OUTPUT);
  pinMode(solB, OUTPUT);
  pinMode(solC, OUTPUT);
  pinMode(gearup, INPUT);
  pinMode(geardown, INPUT);
  pinMode(sol1, INPUT_PULLUP);
  pinMode(man, INPUT_PULLUP);
  pinMode(sol2, INPUT_PULLUP);
  pinMode(sol3, INPUT_PULLUP);
  
  //pins for display
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);

}
//Manual Paddle shift mode
void loop() {
  if(gear == 1 && val4 == LOW){
    digitalWrite(solA, 0);
    digitalWrite(solB, 1);
    digitalWrite(solC, 0);
    one();
  }
  if(gear == 2 && val4 == LOW){
    digitalWrite(solA, 1);
    digitalWrite(solB, 1);
    digitalWrite(solC, 0);
    two();
  }
  if(gear == 3 && val4 == LOW){
    digitalWrite(solA, 1);
    digitalWrite(solB, 0);
    digitalWrite(solC, 0);
    three();
  }
  if(gear == 4 && val4 == LOW){
    digitalWrite(solA, 0);
    digitalWrite(solB, 0);
    digitalWrite(solC, 0);
    four();
  }
  if(gear == 5 && val4 == LOW){
    digitalWrite(solC, 1);
    five();
  }

  //display when reads from the original auto TCU
  
  val=digitalRead(sol1);
  val2=digitalRead(sol2);
  val3=digitalRead(sol3);
  val4=digitalRead(man);
  
  
  if (val == HIGH && val2 == LOW && val3 == HIGH && val4 == HIGH) //gear 1
  {
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  
}
if (val == LOW && val2 == LOW && val3 == HIGH && val4 == HIGH) //gear 2
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  
}
if (val == LOW && val2 == HIGH && val3 == HIGH && val4 == HIGH) //gear 3
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  
}
if (val == HIGH && val2 == HIGH && val3 == HIGH && val4 == HIGH) //gear 4
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
  
}
if (val == HIGH && val2 == HIGH && val3 == LOW && val4 == HIGH) //gear 5
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
   
}




  //takes care of gear switching

  delay(120); //delay to prevent going through gears too quick from holding the button or pressing too long

 gear += digitalRead(geardown) - digitalRead(gearup); // non debounced! But may not be a problem because of the delay by gear change
  if(gear < 1) gear = 1;
  if(gear > 5) gear = 5;//limits to actual gearset
}

//for displaying numbers
void one()  //Writes a #1 on the display
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  
}
void two()  //Writes a #2 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  
}
void three()  //Writes a #3 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  
}
void four()  //Writes a #4 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
  
}
void five()  //Writes a #5 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
   
}
void six()  //Writes a #6 on the display
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  
}
void seven()  //Writes a #7 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  
}
void eight()  //Writes a #8 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
 
}
void nine()  //Writes a #9 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}
1 Like

You already decode the original gear from val to val4 for display. Add code to store the selected gear number also into a variable.

Yes, but i don't know how to do that because i don't have too much programming skills just the basics!

Thats why i'm here seeking for help!

i've tried something like:

int val5 = 0;

val5=digitalRead(sol1 && sol2 && sol3);

i think this will store the readings but i don't know how to use it to inicialize the gear read from the original TCU when i change from auto to manual mode

You have this code already, which you can modify to also save the current gear:

  if (val == HIGH && val2 == LOW && val3 == HIGH && val4 == HIGH) //gear 1
  {
  gear=1; <----------------------------- add this
  digitalWrite(a, LOW);
  ...

DrDiettrich:
You have this code already, which you can modify to also save the current gear:

  if (val == HIGH && val2 == LOW && val3 == HIGH && val4 == HIGH) //gear 1

{
  gear=1; <----------------------------- add this
  digitalWrite(a, LOW);
  ...

There is the answer! You may keep track of the gear even when you are in "auto mode". You also need too (if you really want to make code), keep your code organized and (the most important of all) name the variables what they really are.
Something like the following will be much more appropriated that what you have.

#define MAN LOW
#define AUTO HIGH


int gear = 1;

// output pins for transistor/relays controlled solenoids
int pin_solA = 4;
int pin_solB = 5;
int pin_solC = 1;

// input pins for up down /  with pullup resistors
int gearup = 2;
int geardown = 3;


int pin_sol1 = 14; //from the original TCU-read
int pin_sol2 = 15; //from the original TCU-read
int pin_sol3 = 16; //from the original TCU-read

int pin_man = 17; // switch that change from auto to manual paddle shift

int sol1 = 0; //sol1 to read pin 14
int sol2 = 0; //sol1 to read pin 15
int sol3 = 0; //sol1 to read pin 16
int man = 0; //sol1 to read the switch that change from auto to manual

//for 7 segment display
int b=7, a=6, e=10, d=9, f=11, c=8, g=12;

void setup() {
  pinMode(pin_solA, OUTPUT);
  pinMode(pin_solB, OUTPUT);
  pinMode(pin_solC, OUTPUT);
  pinMode(gearup, INPUT);
  pinMode(geardown, INPUT);
  pinMode(pin_sol1, INPUT_PULLUP);
  pinMode(pin_man, INPUT_PULLUP);
  pinMode(pin_sol2, INPUT_PULLUP);
  pinMode(pin_sol3, INPUT_PULLUP);

  //pins for display
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);

}


//Manual Paddle shift mode
void loop() {

  //display when reads from the original auto TCU

  sol1  = digitalRead(pin_sol1);
  sol2 = digitalRead(pin_sol2);
  sol3 = digitalRead(pin_sol3);
  man  = digitalRead(pin_man);

  if (man == MAN) { // Change MAN gear

    //takes care of gear switching
    gear += digitalRead(geardown) - digitalRead(gearup); // non debounced! But may not be a problem because of the delay by gear change
    if(gear < 1) gear = 1;
    if(gear > 5) gear = 5;//limits to actual gearset

    delay(120); //delay to prevent going through gears too quick from holding the button or pressing too long

    if(gear == 1){  // Change to gear 1
      digitalWrite(pin_solA, 0);
      digitalWrite(pin_solB, 1);
      digitalWrite(pin_solC, 0);
    }
    if(gear == 2){  // Change to gear 2
      digitalWrite(pin_solA, 1);
      digitalWrite(pin_solB, 1);
      digitalWrite(pin_solC, 0);
    }
    if(gear == 3){  // Change to gear 3
      digitalWrite(pin_solA, 1);
      digitalWrite(pin_solB, 0);
      digitalWrite(pin_solC, 0);
    }
    if(gear == 4){  // Change to gear 4
      digitalWrite(pin_solA, 0);
      digitalWrite(pin_solB, 0);
      digitalWrite(pin_solC, 0);
    }
    if(gear == 5){  // Change to gear 5
      digitalWrite(pin_solC, 1);
    }
  }

  else if ( man == AUTO ) { // Catch AUTO gear
    if (sol1 == HIGH && sol2 == LOW && sol3 == HIGH) //gear 1
    {
      gear = 1;
    }
    if (sol1 == LOW && sol2 == LOW && sol3 == HIGH) //gear 2
    {
      gear = 2;
    }
    if (sol1 == LOW && sol2 == HIGH && sol3 == HIGH) //gear 3
    {
      gear = 3;
    }
    if (sol1 == HIGH && sol2 == HIGH && sol3 == HIGH) //gear 4
    {
      gear = 4;
    }
    if (sol1 == HIGH && sol2 == HIGH && sol3 == LOW) //gear 5
    {
      gear = 5;
    }
  }
  
  // Show digits in 7-seg. display
  switch (gear) {
    case 1: one();
            break;
    case 2: two();
            break;
    case 3: three();
            break;
    case 4: four();
            break;
    case 5: five();
            break;
    default: eight();
  }
  
}



//for displaying numbers
void one()  //Writes a #1 on the display
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);

}

void two()  //Writes a #2 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}

void three()  //Writes a #3 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}

void four()  //Writes a #4 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);

}

void five()  //Writes a #5 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);

}

void six()  //Writes a #6 on the display
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}

void seven()  //Writes a #7 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);

}

void eight()  //Writes a #8 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}

void nine()  //Writes a #9 on the display
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);

}

Like I said in the other post: "Don't cross-post"! You will get much more quick (and better) answers.

Ok Ok i think i uderstood i will try to figure it out if it works like i need! thanks to all
speacial thanks to luisilva for the advices!