const int RKELOCK_PIN = 7; // Arduino pin connected to button's pin
const int RKEUNLOCK_PIN = 8; //
const int START_PIN = 2; // Arduino pin connected to relay's pin
const int SWITCH_PIN = 6; //pin for trans shifter switch
const int RUN_PIN = 3; // pin for run position relay
int LbuttonPresses = 0;
int LlastPressCount = 0;
int UbuttonPresses = 0;
int UlastPressCount = 0;
const unsigned long ASD_TIMER = 10000;
unsigned long previousTime = 0; // the time the delay started
bool delayRunning = false; // true if still waiting for delay to finish
void setup() {
Serial.begin(9600); // initialize serial
pinMode(RKELOCK_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(RKEUNLOCK_PIN, INPUT_PULLUP);
pinMode(START_PIN, OUTPUT); // set arduino pin to output mode
pinMode(SWITCH_PIN, INPUT_PULLUP);
pinMode(RUN_PIN, OUTPUT);
}
void checkLed() { // the led task
unsigned long currentTime = millis();
if (RUN_PIN, HIGH)
if (delayRunning && ( currentTime - previousTime >= ASD_TIMER))
{
delayRunning = false; // // prevent this code being run more then once
digitalWrite(RUN_PIN, LOW); // turn led off
Serial.println("Turned Ignition Off");
//previousTime = currentTime;
}
}
void loop() {
unsigned long currentTime = millis();
checkLed();
if (digitalRead(SWITCH_PIN) == LOW)
if (digitalRead (RKELOCK_PIN) == LOW){
LbuttonPresses++; // increment buttonPresses count
delay(250); // debounce switch
}
if (LbuttonPresses == 3) LbuttonPresses = 1; // rollover every third press
if (LlastPressCount != LbuttonPresses) // only do output if the count has changed
{
Serial.print ("Lock Button press count = "); // out to serial
Serial.println(LbuttonPresses, DEC);
if (LbuttonPresses == 2)
{
digitalWrite(RUN_PIN, HIGH);
previousTime = currentTime;
delayRunning = true; // not finished yet
delay (1000);
digitalWrite(START_PIN, HIGH); // turn on led
delay(2000); // wait half a second
digitalWrite(START_PIN, LOW); // turn off led
}
LlastPressCount = LbuttonPresses; // track last press count
}
else if (digitalRead(RKEUNLOCK_PIN) == LOW){
UbuttonPresses++;
delay(250);
}
if (UbuttonPresses == 3) UbuttonPresses = 1; // rollover every third press
if (UlastPressCount != UbuttonPresses) // only do output if the count has changed
{
Serial.print ("UnLock Button press count = "); // out to serial
Serial.println(UbuttonPresses, DEC);
if (UbuttonPresses == 2)
{
digitalWrite(RUN_PIN, LOW);
}
UlastPressCount = UbuttonPresses; // track last press count
}
}