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);
}