transmission control shift

i need to control the two solenoids on a transmission i,m building. the transmission work by turning on/off the solenoids. using the simple button code i am able to turn on a led that represents the solenoid. i attempted to write a code to toggle both solenoids/led when i press a upshot button or a down shift button. could some one help me with the code?
solenoid 1-solenoid 2
1st - on - off
2nd- on - on
3rd- off - on
4th- off - off

//Paddle shift transmition controler
int button = 2; // upshit
int button1 = 4; // down shift
int soleniod1 = 10;
int soleniod2 = 11;
int pressCount = 0;
int count = 0;
int buttonstate1=0;
int buttonstate2=0;

void setup(){
pinMode(soleniod1,OUTPUT);
pinMode(soleniod2,OUTPUT);
pinMode(button,INPUT);
pinMode(button1,INPUT);
}

void loop(){
buttonstate1 = digitalRead(button);
buttonstate2 = digitalRead(button1);

if (button == HIGH){
pressCount=(count + 1);
}
if(button1 == HIGH){
pressCount=(count - 1);
}

switch(pressCount){
case 1: //FIRST GEAR
digitalWrite(soleniod1,HIGH);
digitalWrite(soleniod2,LOW);
break;

case 2: //SECOND GEAR
digitalWrite(soleniod1,HIGH);
digitalWrite(soleniod2,HIGH);
break;

case 3: //THIRD GEAR
digitalWrite(soleniod1,LOW);
digitalWrite(soleniod2,HIGH);
break;

case 4: //OVERDRIVE
digitalWrite(soleniod1,LOW);
digitalWrite(soleniod2,LOW);
break;
}
*/

paddleshift.ino (1.01 KB)

You need to do debouncing to that buttons. (you have one example for that in your IDE)
You need to reset the counters (when they reach maximum and/or minimum), or don’t let they go further.

This is wrong:

  buttonstate1 = digitalRead(button);
  buttonstate2 = digitalRead(button1);
  
  if (button == HIGH){
   pressCount=(count + 1);
  }
  if(button1 == HIGH){
   pressCount=(count - 1);
  }

You should be doing this:

  buttonstate1 = digitalRead(button);
  buttonstate2 = digitalRead(button1);
  
  if (buttonstate1 == HIGH){
   pressCount=(count + 1);
  }
  if(buttonstate2 == HIGH){
   pressCount=(count - 1);
  }

I don’t know if you see the difference.

Or adding de feature that I point earlier:

  buttonstate1 = digitalRead(button);
  buttonstate2 = digitalRead(button1);
  
  if (buttonstate1 == HIGH && pressCount < 4){
   pressCount=(count + 1);
  }
  if(buttonstate2 == HIGH && pressCount > 1){
   pressCount=(count - 1);
  }

Other thing is the initialization of the variable pressCount. You should be doing this:

int pressCount = 1;

and not what you are doing.

You should read also the forum rules here before post. One of the rules say to put the code inside the “code” tag, that you can find in the toolbar.

I don't think luissilva's advice is all that useful. You do NOT want to be counting when the switch IS pressed. You need to count only when the switch BECOMES pressed.

Start with the state change detection example.

Edit: Not yet, anyway. You will need to debounce the switches, if that proves necessary. It depends on what happens after you detect a state change.

Yes you're right PaulS. :roll_eyes:

luisilva: Yes you're right PaulS. :roll_eyes:

I edited my post. Some of your advice was good, just premature.

Are there any safety concerns if the transmission shifts up or down unexpectedly? For example, if this is a vehicle transmission there may be concerns about over-revving the engine, or causing excessive engine braking leading to loss of control.

Another Newbie with an Electronic Transmission Controller need.

For a Mercedes/Chrysler/Jeep. 722.6 5 speed

Im not sure is previous answers would work for my application. Hi guys, I am a huge fan of Arduino and big day dreamer who is tired of day dreaming, so I finally bought a Mega 2560 to bring my dreams to reality.

Problem is I've never programmed before. Did Electronics/Mechanical engineering in school but that was before Arduinos.

If this topic has been covered before and I can be pointed into the right direction I would appreciate it. I have a 5 speed automatic transmission I'd like to control also with possible paddle shift mode.

It has a total of 6 solenoids. 3 solenoids to shift 1st to 5th and back to 1st (1st-2nd/4th-5th uses the same solenoid)

4 solenoid is for Torque Converter Clutch

5 solenoid is for Modulated Pressure Control

6 solenoid is the Shift Pressure Control

(Solenoids here are not in any articular order)

I have played around with some sketches and has basic understanding on it but I'm still learning other language aspect of the sketches.

The shift pattern of this transmission is as follows

GEAR | 40% duty cycle| 33%duty cycle SHIFTS | 1-2/4-4 | 2-3 | 3-4 | MOD PC #5 | SHIFT PC #6 | TCC |

1ST --- OFF -- OFF - OFF - PWM OFF OFF

SHIFT --- ON -- OFF - OFF - PWM PWM OFF


2ND --- OFF -- OFF - OFF - PWM OFF PWM

SHIFT --- OFF -- ON - OFF - PWM PWM PWM

3RD --- OFF -- OFF - OFF - PWM OFF PWM

SHIFT --- OFF -- OFF - ON - PWM PWM PWM

4TH --- OFF -- OFF - OFF - PWM OFF PWM

SHIFT --- ON -- OFF - OFF - PWM PWM PWM

5TH --- OFF -- OFF - OFF - PWM OFF PWM

I am known to over engineer things. Did I make this too complicated?

Any input would be greatly appreciated. Thanks.