Hi, I am using a Nano to control my steering wheel buttons that used to be used for cruise control to control my Mustang's Tesla Model 3 motor instead of switches on the console.
My question is when powering up the Nano need to have my designated Park LED come on, go HIGH, and then have it go LOW when I activate the Park off, Drive, Reverse or Neutral and come back on when Park on is pressed again? I'm sure there is a way I'm just having the issue to turn it off. I can turn it on but then when I press say the Drive button the led goes off while it's pressed but comes back on. I need it to shut off until I press the Park button again or if the ignition is shut off then back on. It seems really simple but I'm having a mental block it seems with the logic. I have all functions working relays but having issues with the indicator lights. One of the issues is that all the motor controller inputs are momentary 12 volts to the M3 motor controller. Thus the relays. Here's the code.
/*
Send data from multiple steering wheel switches through a pair of wires without using a digital protocol only a program resistor is needed for each switch and an analog voltage from the resistor
is detected and momentary switch enable Rev Date 01-01-2022
*/
int commandState;
void setup() {
Serial.begin(9600);
pinMode (2, HIGH); // On button = Park setting in controller, Park brake enable. Relay #1:
pinMode (3, HIGH); // Set+ button = Drive setting in controller. Relay #3:
pinMode (4, HIGH); // Set- button = Reverse setting in controller Relay #4 :
pinMode (5, HIGH); // Off button = Park brake off Relay #5:
pinMode (6, HIGH); // Resume button = Neutral setting in controller. Relay #2:
pinMode (2, OUTPUT); // On button = Park setting in controller, Park brake enable. Relay #1:
pinMode (3, OUTPUT); // Set+ button = Drive setting in controller. Relay #3:
pinMode (4, OUTPUT); // Set- button = Reverse setting in controller Relay #4 :
pinMode (5, OUTPUT); // Off button = Park brake off Relay #5:
pinMode (6, OUTPUT); // Resume button = Neutral setting in controller. Relay #2:
}
void loop() {
commandState = analogRead(A0);
Serial.println(commandState);
if(commandState >=150 && commandState <=210){
digitalWrite (2, HIGH);
digitalWrite (3, HIGH); //All pins HIGH this section:
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (6, HIGH);
}
else if(commandState >=300 && commandState <=350){
digitalWrite (2, LOW); //Park brake On, motor in Park mode:
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (6, HIGH);
digitalWrite (7, HIGH); //Test LED
}
else if(commandState >=450 && commandState <=530){
digitalWrite (2, HIGH);
digitalWrite (3, LOW);
digitalWrite (4, HIGH); //Resume = Neutral:
digitalWrite (5, HIGH);
digitalWrite (6, HIGH);
}
else if(commandState >=610 && commandState <=650) {
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, LOW); //Set+ = forward drive enable:
digitalWrite (5, HIGH);
digitalWrite (6, HIGH);
}
else if(commandState >=750 && commandState <=800) {
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH); //Set- = reverse drive enable:
digitalWrite (5, LOW);
digitalWrite (6, HIGH);
}
else if(commandState >=1000 && commandState <=1023) {
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH); //Off button = Park brake Off,
digitalWrite (6, LOW);
digitalWrite (7, LOW); //Test LED:
}
delay(50);
}