If / Else Statements (ALARM deactivate switch with timer)

I have a tractor that I'd like to build an alarm for. Here's what I'd like to do:

If - starter solenoid is activated (Input 1 we'll say) AND - deactivation switch (Input 2 momentary push button) is pressed within 120 seconds

Do nothing

................................................. ELSE

Beep horn once every second

I would think I can use the example sketch 'Button' for my two inputs. My main equestion is: How do I allow a button press to be read ANY time within the 120 seconds?

Also, maybe equally important... can the Atmega 356 chip handle 14.5VDC at a digital input?

Here is my rough sketch. I wasn't sure how to infintiely (until reset) loop the beeping of the horn. But this should be a start... maybe not a good :D start... but a start.

const int buttonPin = 2;     // the number of the pushbutton pin connected to the Starter Solenoid
const int buttonPin2 = 3;     // the number of the pushbutton pin connected to the deactivation N/O Momentary switch 
const int ledPin =  13;      // the number of the horn output relay pin

// variables :
int buttonState = 0;         // variable for reading the Starter Solenoid status
int buttonState2 = 0;        // variable for reading the deactivate pushbutton status
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
    // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
 delay(120000);                       // wait 120 seconds
  and
  (buttonState2 = digitalRead(buttonPin2)  // check for deactivation switch signal      
    // do nothing if deactivation is pressed:
    digitalWrite(ledPin, LOW);
    
  } else {
//  loop this code infinitely until reset is pressed (not sure how)    
    // turn LED off:
    digitalWrite(ledPin, HIGH);
    delay(500); // beep 500 ms
    digitalWrite(ledPin, LOW);
    delay(1000); // wait 1000 ms
  }
}

That's not going to work if the deactivate button is pressed and released during the 120 second delay. The sketch will never see it.

This tutorial teaches how to do more than one thing at a time with Arduino. Watching a timer and a button at the same time uses the same technique as blinking 2 leds or cooking 3 things in the commonsense example.

http://gammon.com.au/blink

Spend an hour or so messing with it to see the whole workings.

Also, maybe equally important... can the Atmega 356 chip handle 14.5VDC at a digital input?

NO! 5 volt MAXIMUM, but you can use a voltage divider to bring 14.5V down below 5V.
sw-12V.png

sw-12V.png

Ok thanks. I was thinking it couldn't handle 14.5 vdc, but wasn't sure. I like to ask questions vs letting the old smoke out... lol.

As to the alarm code design, I may go ahead and buy something off the shelf or use a plc and revisit sharpening my Arduino skills when I have more time.

Thanks to those who've offered suggestions!