timer sketch

how can i make a timer sketch with push button for 10s and then off . once its off it doesn't loop until the switch is and on again

if the switch is detected, delay(10000)

Edit - if the switch is detected, turn on, delay(10000), turn off

khalilshehadeh: how can i make a timer sketch with push button for 10s and then off . once its off it doesn't loop until the switch is and on again

Try rephrasing your question, include everything that needs to happen.

Show us the work you have done so far.

.

Love these questions. Now This is the Proper way to do this without delays by using millis(). Using delays will create situations in the future of your code that will always create problems... unless your code remains simple.

#define ButtonPin 5 // Short Button Pin 5 to ground to Trigger Timer
#define LEDPin 13
#define OnDelay 10000  // 10 Seconds

void setup() {
  // put your setup code here, to run once:
  pinMode(ButtonPin, INPUT_PULLUP);
  pinMode(LEDPin, OUTPUT)
}

void loop() {
  // put your other code here, to run repeatedly No blocking Cone! (delay() is forbidden!):

  static bool TimerGo = false;
  static unsigned long Timer;  // Keyword static keeps the value each loop and doesn't require the variable to be global
  if(!Timer && (digitalRead(ButtonPin) == LOW)){
    Timer = millis();
    TimerGo = true;
    TurnOn();  // function call to do action at beginning of timer
    
  }
  if ((millis() - Timer) >= (OnDelay)) {
    Timer = 0;
    TimerGo = false;
    TurnOff(); // function call to do something at end of timer
  }
  if(TimerGo) TimerActive(); // Function to call repeatedly when timer is on 
}
void TurnOn(){
  digitalWrite(LEDPin,HIGH);
}
void TurnOff(){
  digitalWrite(LEDPin,LOW);
}
void TimerActive(){

}

We will be happy to help you with all the parts of this blink without delay style code Just ask :)

Z