I am building a controller for the automatic transmission in my rock crawler. the intention is to provide full manual control of the 4 forward gears. I have the controller shifting the gears as it needs to. i just need to add a neutral feature using an input pin. I have a bit of code written but it is not working correctly.
int gear = 1;
// output pins for transistor controlled solenoids
int solA = 7;
int solB = 6;
// input pins for up down / with pullup resistors
int gearup = 9;
int geardown = 10;
// input pin for neutral safety switch(nss)
int nss = 8;
void setup() {
pinMode(solA, OUTPUT);
pinMode(solB, OUTPUT);
pinMode(gearup, INPUT);
pinMode(geardown, INPUT);
pinMode(nss, INPUT_PULLUP);
}
void loop() {
// intention is when nss pin 8 is high it will show GEAR 4 when the shift lever is in park, reverse or neutral the soleniod state for gear 4 serves as a neutral.
//I cannot make this feature work!!!
if (nss == HIGH) {
digitalWrite(solA, 0);
digitalWrite(solB, 0);
}
//intention is when nss is pulled low by placing the shift leever into drive thus grounding pin 8 it will start in first gear
// i cannot make this work!!
if (nss == LOW) {
digitalWrite(solA, 1);
digitalWrite(solB, 0);
}
//this section works as it should
if (gear == 1) {
digitalWrite(solA, 1);
digitalWrite(solB, 0);
}
if (gear == 2) {
digitalWrite(solA, 1);
digitalWrite(solB, 1);
}
if (gear == 3) {
digitalWrite(solA, 0);
digitalWrite(solB, 1);
}
if (gear == 4) {
digitalWrite(solA, 0);
digitalWrite(solB, 0);
}
//takes care of gear switching
delay(180);//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 > 4) gear = 4;
//limits to actual gearset
}
please advise me on how to make the neutral safety switch active in this code.