Hey everyone! I am struggling and am in need of some expert advice.....A little background, I am a mechanic by trade and hobby and can and have fixed everything from microwaves to small aircraft and almost everything in between. But this programming language is kicking my butt! I just can't visualize it like I can most other things. Any way on to my problem.
I am building a push button start/stop with RFID "key" for my f150 Lightning, and eventually I want to add some other options too, but one thing at a time. I have watched so many tuturials that, I thought I was going blind, tried using the libraries and still struggled. What I want is to have the rfid chip in my pocket, get in the truck, the RFID goes "green" allowing the push button to start the truck, by holding down the button for 2 seconds, turn on the ignition relays and at 3 seconds engage the starter until I let off the button. Once the truck is started I want to run an input from my tach to disable the starter. If the RFID chip is out of range, then the push button will still turn on the ACC (like turning the key back) so I can listen to radio etc....
I have written the program and laid it out on my breadboard so that "inputPin1" (the push button) will toggle output "ledPin" (the ignition relay output) only if "inputPin2" (input signal from the RFID module) is "high." And it turns on the "ledPin" just fine, but I want to be able to turn off "ledPin" regardless of what state "inputPin2" is in..... I can also toggle the "accPin" (the output to control the ACC relay)
with the "inputPin1" if "inputPin2" is "low" but my debounce doesn't work on that function, so the results are subpar, how do I debounce this function alone? Thanks EVeryone
int ledPin = 11; // led in place of ignition relay for prototyping purposes only
int inputPin1 = 2; // input from button to start the truck
int inputPin2 = 7; // input from rfid relay to allow truck to start
int accPin = 12; // accPin to turn on accesories.
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean currentButton2 = LOW;
boolean lastButton2 = LOW;
boolean ledOn = false;
boolean accOn = false;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
pinMode(accPin, OUTPUT);
}
boolean debounce(boolean last)
{
boolean currentButton = digitalRead(inputPin1);
if (last != currentButton);
{
delay(5);
currentButton = digitalRead(inputPin1);
}
return currentButton;
}
boolean debounce2(boolean last2)
{
boolean currentButton2 = digitalRead(inputPin1);
if (last2 != currentButton2);
{
delay(5);
currentButton = digitalRead(inputPin1);
}
return currentButton2;
}
void loop()
{
currentButton = debounce(lastButton);
if (digitalRead(inputPin1) == LOW && lastButton == HIGH && digitalRead(inputPin2) == HIGH && lastButton == HIGH){
ledOn =! ledOn;
}
{
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}
{
currentButton2 = debounce(lastButton2);
if (digitalRead(ledPin) == LOW && lastButton2 == HIGH && digitalRead(inputPin2) == LOW){
accOn =! accOn;
}
{
lastButton2 = currentButton2;
digitalWrite(accPin, accOn);
}
}
}
Oh and why does this text box shake up and down as you type making it a real pia to see what youre typing....