Mode selecting with two buttons

Hi!!
I need to make mode selecting with two buttons.
First button (+) will choose first mode, if you press it again, second, third and so on..
The second one (-) will decrease the current mode by 1 (if it was 7th, it will be 6th)

In first mode the relay should turn on after 30 seconds, in second mode it should turn on after 60sec and so on to the mode eight.

I'm sorry in advance for grammar and spelling errors :slight_smile:

You need to look at the state change detection example. Incrementing or decrementing a value each time a switch BECOMES pressed is easy.

Do NOT use delay(). You will not be reading the switches while the delay() is happening.

Look at the blink without delay example to see how not to use delay.

Yes delay(). too easy and system stopped.
using millis maybe timer or pin interrupt pins with which model do you use?

Arlove:
Yes delay(). too easy and system stopped.
using millis maybe timer or pin interrupt pins with which model do you use?

Millis(). No way do you need timers or interrupts for this.

My current code:

const int switchPin = 13;
const int switchPin2 = 11;

int led1 = 7;   //led mode pins
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 9;
int led8 = 8;
int relay = 12;

int mode = 0;
boolean buttonState;
boolean buttonState2;

void setup() {
  pinMode(switchPin, INPUT);
  pinMode(switchPin2, INPUT);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(relay, OUTPUT);
 }
 
 void loop() {
   
  buttonState = digitalRead(switchPin);
  buttonState2 = digitalRead(switchPin2);
  
   buttoncheck(); //calls to the void buttoncheck() 
   if(mode == 0)
    {
      mode0(); 
    }
    if(mode == 1)
    { 
      mode1(); 
    }
    if(mode == 2)
    {
      mode2(); 
    }
    if(mode == 3)
    {
      mode3(); 
    }
    if(mode == 4)
    {
      mode4(); 
    }
    if(mode == 5)
    {
      mode5(); 
    }  
   if(mode == 6)
    {
      mode6(); 
    }  
   if(mode == 7)
    {
      mode7(); 
    }  
   if(mode == 8)
    {
      mode8(); 
    }  
   
}

void buttoncheck() {
     
  if (buttonState == LOW) {
    ++mode;
    delay(80);
  }
  if (buttonState2 == HIGH) {
    --mode;
    delay(80);
  }

  if (mode < 0)
  { mode = 0;
  }
  if (mode > 8)
  { mode = 8;
  }

}

void mode0()
  {
    buttoncheck;
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
   } 
void mode1()
  { 
    buttoncheck;
    digitalWrite(led1, HIGH);
    delay(10000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
   }
  
 void mode2()
  { 
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    delay(20000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
    }
  
  void mode3()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    delay(30000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
    }
  
  
  void mode4()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    delay(40000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
    }
  
  void mode5()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    delay(50000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
    }
  
  void mode6()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);
    delay(60000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);
    }
  
  void mode7()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
    delay(30000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    digitalWrite(led8, LOW);
    }
  
  void mode8()
  {
    buttoncheck;
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
    digitalWrite(led8, HIGH);
    delay(70000);
    digitalWrite(relay, HIGH);
    delay(500);
    digitalWrite(relay, LOW);
    }
   buttoncheck(); //calls to the void buttoncheck()

Really? I'd have never guessed.

You didn't look at the state change detection example, did you?