Hi PaulS and Arrch,
Thanks a lot for your help so far !
i do think i have something (by luck) which is working:
int currState;
int prevState = HIGH; // Assumes LOW means pressed
const int buttonPin = 2; // Connect the switch to this pin and to ground; no other wires or resistors needed
const int ledPin = 13; // My LED
// Variables will change:
long previousMillis = 0; // will store last time LED was updated
int pressCount = 0;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10000; // interval for on time (milliseconds)
void setup()
{
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(ledPin, OUTPUT);
}
void loop()
{
currState = digitalRead(buttonPin);
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;
if (pressCount == 1) // here to switch on the LED
digitalWrite(ledPin,HIGH);
// here should be the timmer with millis(), ?
// after 5min i guess pressCount = 2
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
pressCount = 2; //turn off
}
if (pressCount == 2) // here the switch off within the 5min
digitalWrite(ledPin,LOW);
// 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
}