timing button presses

I am making a home alarm. I have one button to activate and de-activte.

press and hold for 2 seconds and it re-sets to occupied (not armed)

press and hold for 1 second and it will toggle from the current state to the opposite state
from armed to not-armed

immediately upon pressing, the button, an LED will light, green for not-armed and red for armed.
also, if the state is not-armed and the sensors show movement, the red LED would flash. this would allow the person setting to know not hold for the full second, but to go figure what is wrong.

my problem is about the button.

should I be trying to use a series of IF statements ? or is a State Machine better ?

suggestions ?

I'm not sure that a state machine and a series of IF statements are mutually exclusive.

I do think you need to think of your project as a state machine. You want it to switch states in certain circumstances.

I think I would have a bigger distinction between the button press times. One second is not a lot different from "immediate" for a human so I think I would have the short one at least 2 seconds and then I think I would have the long one about 5 or 6 seconds.

But there is a problem. If the user presses the button for 2 seconds and intends to continue holding it for 5 seconds how can the Arduino know (after 2 seconds) to keep waiting?

I think you need to record the time when the button goes from HIGH to LOW (assuming active LOW) and again (in a separate variable) when it goes from LOW to HIGH.

Only after it has been LOW and goes HIGH again do you take any notice of the time - by subtracting the first time from the last time.

I also think that the short press should be determined as longer than 2 secs and less than 3 (or 4) secs - in other words, not exactly 2000 millisecs. You could, perhaps, have an LED light up to show when at least 2 secs has passed and again when at least 5 secs has passed. Or, more simply - release the button after the LED lights or keep holding it until it goes out again.

...R