Button Input Delay Problem

Hi, I need help on my coding. I am trying to build smart clothesline system.I have problem when i pressed the button there is huge delayed for LED to turn ON.

Here is my code.

#include <Stepper.h>
#include <dht.h>
#include <Button.h>
#include <LiquidCrystal.h>
#define DHT11_PIN 7
LiquidCrystal lcd(13, 12, 5, 4, 3, 2);

dht DHT;


const int stepsPerRevolution = 600;                             // the number of steps per revolution
// for your motor


Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);            // initialize the stepper library on pins 8 through 11:

// lowest and highest sensor readings:
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum
int motorstate=0;

const int ledPin1 =  15;      // the number of the LED pin
const int ledPin2 =  16; 
const int ledPin3 =  17; 
const int ledPin4 =  18; 
const int ledPin5 =  19; 

Button button = Button(6,PULLUP);
byte pressCount = 0;


void setup() 
{
lcd.begin(16, 2);              // set up the LCD's number of columns and rows:
Serial.begin(9600);           // initialize the serial port:
myStepper.setSpeed(60);
  
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
  
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);

byte pressCount = 0;
  
}

void loop() 
{  
Serial.println(pressCount);
if(button.uniquePress())
     pressCount++;
   
  switch(pressCount)
  {
      case 1:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, LOW);
         digitalWrite(ledPin3, LOW);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
         delay(1000);
         break;
       
         
     case 2:
          digitalWrite(ledPin1,HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, LOW);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
         delay(1000); 
         break;
        
         
     case 3:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
         delay(1000);
         break;
         

     case 4:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, HIGH);
         digitalWrite(ledPin5, LOW);
         delay(1000);
         break;
         
         
      case 5:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, HIGH);
         digitalWrite(ledPin5, HIGH);
         pressCount = 0;
         delay(1000);
         break;
  }

 
  myStepper.setSpeed(60);
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000); 

   // read the sensor on analog A0:
  int sensorReading = analogRead(A0);
  int range = map(sensorReading, sensorMin, sensorMax, 0, 3);


  switch (range)
  {
    
 case 0:                                            // Sensor getting wet
    Serial.println("Flood");
    break;
 
 case 1:                                           // Sensor getting wet
    lcd.clear();
    lcd.setCursor(2, 1);
    lcd.print("Rain Warning");
    if (motorstate==0)
    {
    runmotor(); 
    }
    delay(1000);
    break;
    
 case 2:                                       // Sensor dry
    myStepper.setSpeed(60);
    lcd.clear();
    lcd.setCursor(2, 1);
    lcd.print("Not Raining ");
    motorstate=0;
    delay(1000);
    break;
  }
}

void runmotor()
{
   myStepper.step(600);
   delay (1000);
   motorstate=1;
}

That "huge delay" is because you use huge delay()'s ;) If you want to have no delay you have to get rid of ALL of them. See Blink without delay.

byte pressCount = 0;

That variable goes out of scope a few nanoseconds later. Why did you bother typing the statement?

Thanks septilion...it works.I have a few additional question regarding the presscount button. I trying to make time selector for each time button is pressed. For example case 1, event will trigger after 5 sec button is pressed and case 2,event will trigger after for 10 sec after the button is pressed and so on. I already write the code..the problem is each time the button pressed,it must wait a previous case to complete. Is there any way to fix this?

sorry forgot the code.
Here is the code

#include <Button.h>

// constants won't change. They're used here to
// set pin numbers:
   
const int ledPin1 =  15;      // the number of the LED pin
const int ledPin2 =  16; 
const int ledPin3 =  17; 
const int ledPin4 =  18; 
const int ledPin5 =  19; 
int buttonstate=0;

Button button = Button(6,PULLUP);

unsigned long currentMillis = 0;

unsigned char counter = 0;
 
unsigned char previousCounter = 0;
unsigned int interval=100;



 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  
  // initialize the pushbutton pin as an input:

  currentMillis = millis();
  Serial.begin(9600);   
}
byte pressCount = 0;

void loop() 
{
  currentMillis = millis();

  
if(button.uniquePress())
     pressCount++;
   

  switch(pressCount)
  {
     case 1:
         digitalWrite(ledPin1, LOW);
         digitalWrite(ledPin2, LOW);
         digitalWrite(ledPin3, LOW);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
      
         break;
       
      case 2:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, LOW);
         digitalWrite(ledPin3, LOW);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
         if (buttonstate==0)
          {
         
          for (int x=0; x<1000; x++)
          { 
           counter++; // simulate millis()
           Serial.println(counter);
           unsigned char currentCounter = counter;
           if ((unsigned char)(currentCounter - previousCounter) >= interval)
           { 
             previousCounter = currentCounter;
          }
          }
          buttonstate=1;
          Serial.println("Trigger Event!");
          }
          
         break;
       
         
     case 3:
          digitalWrite(ledPin1,HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, LOW);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW); 
            if (buttonstate==1)
          {
         
          for (int x=0; x<1500; x++)
          { 
           counter++; // simulate millis()
           Serial.println(counter);
           unsigned char currentCounter = counter;
           if ((unsigned char)(currentCounter - previousCounter) >= interval)
           { 
             previousCounter = currentCounter;
          }
          }
          buttonstate=2;
          Serial.println("Trigger Event!");
          }
         break;
        
         
     case 4:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, LOW);
         digitalWrite(ledPin5, LOW);
          if (buttonstate==2)
          {
         
          for (int x=0; x<2000; x++)
          { 
           counter++; // simulate millis()
           Serial.println(counter);
           unsigned char currentCounter = counter;
           if ((unsigned char)(currentCounter - previousCounter) >= interval)
           { 
             previousCounter = currentCounter;
          }
          }
          buttonstate=3;
          Serial.println("Trigger Event!");
          }
      
         break;
         

     case 5:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, HIGH);
         digitalWrite(ledPin5, LOW);
      if (buttonstate==3)
          {
         
          for (int x=0; x<2500; x++)
          { 
           counter++; // simulate millis()
           Serial.println(counter);
           unsigned char currentCounter = counter;
           if ((unsigned char)(currentCounter - previousCounter) >= interval)
           { 
             previousCounter = currentCounter;
          }
          }
          buttonstate=4;
          Serial.println("Trigger Event!");
          }
         break;
         
         
      case 6:
         digitalWrite(ledPin1, HIGH);
         digitalWrite(ledPin2, HIGH);
         digitalWrite(ledPin3, HIGH);
         digitalWrite(ledPin4, HIGH);
         digitalWrite(ledPin5, HIGH);
          if (buttonstate==4)
          {
         
          for (int x=0; x<3000; x++)
          { 
           counter++; // simulate millis()
           Serial.println(counter);
           unsigned char currentCounter = counter;
           if ((unsigned char)(currentCounter - previousCounter) >= interval)
           { 
             previousCounter = currentCounter;
          }
          }
          buttonstate=0;
          Serial.println("Trigger Event!");
          }
          pressCount=0;
         break;
}
}

Tip one, watch your indentation. You make it hard on yourself by messing that up. Press Ctrl+T to let the IDE fix it for you.

And next, that's because when the button is pressed you don't know know if that's the last press...

And what are all those for loops for? Just let the loop do the looping and check IN THE LOOP if you need to change led stuff.

Also, a switch is a terrible approach here. You KNOW the time is pressCounter x 5 seconds. Just use that. Saves you from rewriting the 99,9% same code for each case...

If you start writing nearly the same code again you have to think again because then there is a better way ;)