Timer

Hello all
I want to build a project that has a single button and when pressed shines led a certain period of time, for example, half an hour and when you press it again multiplied term to become an hour and so on.

Please Help

See if you can follow this:
Button pressed, capture the start time.
If timer was already running, add 30 minutes to the timer duration.
Every pass thru loop, see if the time now minus the start time is more than the timer duration, and if so, stop.

byte buttonPin = 2; // button press to connect pin to Gnd
byte ledPin = 13; // onboard LED, High is on
unsigned long currentTime;
unsigned long startTime;
unsigned long duration = 1800000; // 1000 ms/S * 60S/min * 30 min
unsigned long timeToGo = duration;
byte timeRunning;
void setup(){
pinMode (buttonPin, INPUT_PULLUP);
pinMode (ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
currentTime = millis();
if (digitalRead(buttonPin) == LOW){
  if( timeRunning == 1){
  timeToGo = timeToGo + duration;
  }
else {
  startTime = currentTime; // capture start time
  timeRunning = 1;
  }
digitalWrite (ledPin, HIGH);
Serial.println("adding half hour");
delay(300); // crude button debounce, no more than ~3 presses per second allowed
}
if ((currentTime - startTime) >=timeToGo ){
  digitalWrite (ledPin, LOW);
  timeRunning = 0;
  Serial.println("time is up");
  }
}

Thanks very much :slight_smile:

wooooooooooow It's a beautiful site Thank you very much again I had the pleasure to meet you