Timer, very simple and yet ....

Hello everyone.
I discovered the Arduino modules.
I want to create a module that has 4 different timer choices + 1 stop function.
However, I can not do it.
Here is my code
Thank you in advance

Multi-Temporisation_1.ino (1.81 KB)

And what's the problem with it? What do you expect? What have you tried?

Aka, we do need more details :slight_smile:

Not:

cas0://durée 5s

But

case 0://durée 5s

‘case’ is not the same as ‘cas’

Get rid of the delay()s.

Read:

https://forum.arduino.cc/index.php?topic=223286.0

Thank you.
The syntax was indeed not good.

But I can not get the function I want.
When I press the button, I want to have the tempo 1 loop 5s On, 5s Off, 5s On, etc ...
When I press again, the tempo goes to 10s, but always with infinite cycles
Etc...
With my code the tempo does not work in loop

Use CTRL T to format your code.
Attach your current ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

'm progressing ... but it does not work
Now it's good, I have my timing loop, but with the button, I do not go from one loop to another ....
Why ?
Here is my new program

Multi-Tempo.ino (2.46 KB)

Richard764:
'm progressing ... but it does not work
Now it's good, I have my timing loop, but with the button, I do not go from one loop to another ....
Why ?
Here is my new program

Hi Richard, attaching code the way you have makes it difficult for people to easily read it and give you advice. Please re-read larryd's post 2 above this one to make your code more accessible.

Sorry, I did not understand because my English is light.

I have since succeeded, but I still have a problem.
My logic is not the right one. Because I have to stay with my finger on the push button for the command to be accepted.
There for my test, I have a delay of 1/2/3 / 4s, but after that will be 5/10/15 / 20s. I can not leave the doight pressed for 40s.
So this code works, but my logic is not good

/*
  Multi-Temporisation

  Différentes temporisations
  Choix par bouton poussoir
  4 temporisations 5/10/15/20s + fonction Arrêt
*/

int pinBouton = 2;
//int pinLED = 13;
int etatAllumage;


// the setup function runs once when you press reset or power the board
void setup() {
  // initialise entrée/sortie
  Serial.begin(9600);
  pinMode(pinBouton, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  etatAllumage = 0;
}

// the loop function runs over and over again forever
void loop() {

  //lecture de l'état du bouton et stockage dans etatBouton
  boolean etatBouton = digitalRead(pinBouton);

  //test des conditions
  if (etatBouton == HIGH) { //test si bouton est appuyé

    Serial.print("etat allumage : " );
    Serial.print(etatAllumage);
    Serial.println();

    //on incrémente le modulo
    etatAllumage = etatAllumage + 1;

    //on teste le modulo et on corrige
    if (etatAllumage == 5) {
      etatAllumage = 0;
    }
  }
  switch (etatAllumage) {
    case 0 : //durée 1s
      digitalWrite(LED_BUILTIN, HIGH);   // Allume la LED
      delay(1000);                  // Attend 1s
      digitalWrite(LED_BUILTIN, LOW);    // Eteint la LED
      delay(1000);                  // Attend 1s
      Serial.println("Tempo 1s");
      break;
    case 1 : //durée 2s
      digitalWrite(LED_BUILTIN, HIGH);   // Allume la LED
      delay(2000);                  // Attend 2s
      digitalWrite(LED_BUILTIN, LOW);    // Eteint la LED
      delay(2000);                  // Attend 2s
      Serial.println("Tempo 2s");
      break;
    case 2 : //durée 3s
      digitalWrite(LED_BUILTIN, HIGH);   // Allume la LED
      delay(3000);                  // Attend 3s
      digitalWrite(LED_BUILTIN, LOW);    // Eteint la LED
      delay(3000);                  // Attend 3s
      Serial.println("Tempo 3s");
      break;
    case 3 : //durée 4s
      digitalWrite(LED_BUILTIN, HIGH);   // Allume la LED
      delay(4000);                  // Attend 4s
      digitalWrite(LED_BUILTIN, LOW);    // Eteint la LED
      delay(4000);                  // Attend 4s
      Serial.println("Tempo 4s");
      break;
    case 4 : //Arrêt
      digitalWrite(LED_BUILTIN, LOW);    // Eteind la LED
      Serial.println("Arrêt");
      break;
      //etatAllumage = etatAllumage + 1;
  }
  //etatAllumage = etatAllumage + 1;
  //delay(200);
}

larryd nailed this for you earlier on - you need to get rid of the delays in your code.

This is a classic use for millis in the form of the IDE's blink without delay example or
Robin2's Doing several things at once thread.