I assumed there must be a simple way to do this.
There is. Perhaps not as simple as you'd like. The debouncing stuff and timed hold stuff in Arrch's code is a bit overkill.
Here's something a bit simpler, but not complete. There are comments though, that explain what else you need to do/add.
int currState;
int prevState = HIGH; // Assumes LOW means pressed
const int somePin = 2; // Connect the switch to this pin and to ground; no other wires or resistors needed
int pressCount = 0;
void setup()
{
pinMode(somePin, INPUT);
digitalWrite(somePin, HIGH);
}
void loop()
{
currState = digitalRead(somePin);
if(currState != prevState)
{
// The switch was just pressed or just released
if(currState == LOW)
{
// Aha, it was just pressed
pressCount++;
if(pressCount > 2)
pressCount = 1;
}
}
prevState = currState;
// Now, do something based on pressCount
// 1 means pressed once - turn on LED
// 2 means pressed twice - turn off LED
// When you turn the LED on, note the time
// If LED is on and has been on for the required time,
// set pressCount to 2, so that next time around, the
// LED will get turned off
}
Look at the blink without delay example for how to use millis() to determine (relative) times. Use a boolean to keep track of the LED state. Set it to true when you turn the LED on (using that state variable). Set it to false when you turn the LED off. Then, the value will tell you whether the LED is on, or not.