Switch case? (Hijack)

sir,

I need one pus button comand in my relay program mines push button press the start program delay time.

my code heare

define RELAY1 7 //Defining the pin 7 of the Arduino for the 4 relay module

define RELAY2 6 //Defining the pin 6 of the Arduino for the 4 relay module

define RELAY3 5 //Defining the pin 5 of the Arduino for the 4 relay module

define RELAY4 4 //Defining the pin 4 of the Arduino for the 4 relay module

void setup() { pinMode(RELAY1, OUTPUT); //Defining the pin 7 of the Arduino as output pinMode(RELAY2, OUTPUT); //Defining the pin 6 of the Arduino as output pinMode(RELAY3, OUTPUT); //Defining the pin 5 of the Arduino as output pinMode(RELAY4, OUTPUT); //Defining the pin 4 of the Arduino as output }

void loop() { digitalWrite(RELAY1,LOW); // This will Turn ON the relay 1 delay(5000); // Wait for 5 seconds digitalWrite(RELAY1,HIGH); // This will Turn the Relay off delay(5000); // Wait for 5 seconds

digitalWrite(RELAY2,LOW); // This will Turn ON the relay 2 delay(5000); // Wait for 5 seconds digitalWrite(RELAY2,HIGH); // This will Turn the Relay Off delay(5000); // Wait for 5 seconds

digitalWrite(RELAY3,LOW); // This will Turn ON the relay 3 delay(5000); // Wait for 5 seconds digitalWrite(RELAY3,HIGH); // This will Turn the Relay Off delay(5000); // Wait for 5 seconds

digitalWrite(RELAY4,LOW); // This will Turn ON the relay 4 delay(5000); // Wait for 5 seconds digitalWrite(RELAY4,HIGH); // This will Turn the Relay Off delay(5000); // Wait for 5 seconds

}

push button press the start program delay time

And the pushbutton will do what with the relays?

Add some global variables:

byte currentState;
byte previousState;

byte pusPin = xxx;

in setup(), add:

   pinMode(pusPin, INPUT_PULLUP);

in loop(), add:

   currentState = digitalRead(pusPin);
   if(currentState == LOW)
   {
      // Do nothing, because there are no requirements for when the switch is pressed
   }
   else
   {
      // Do nothing, because there are no requirements for when the switch is not pressed
   }

   if(currentState != previousState)
   {
      if(currentState == LOW)
      {
         // Do nothing, because there are no requirements for when the switch has become pressed
      }
      else
      {
         // Do nothing, because there are no requirements for when the switch has become released
      }
   }
   previousState = currentState;

rksharma: I need one pus button comand in my relay program mines push button press the start program delay time.

That did not translate well. My guess is that you mean:

"I want to add a pushbutton to my sketch. I want the sketch to wait for the button to be pushed before starting a cycle of turning relays on and off."

To add a pushbutton, connect it between an unused pin and Ground.

In setup(), set that pin's pinMode() to INPUT_PULLUP. The pin will read as HIGH unless the button is pressed.

Where you want to wait for a button press, add:

   while (digitalRead(BUTTON_PIN) == HIGH) {/*Do Nothing*/}