serial monitor & variable are not changed until loop function complete

i made a sketch of blinking led according to my own time related with variables.
i wrote code also to display variable in serial monitor, as when i changed them from buttons,
but variable are not being changed (& not being displayed in serial monitor) same time on pressing buttons,.they are wait till led on led off function end. i want to make change in variable & display it on serial monitor at same time ,when i pressed buttons,although led on led off function complete or not. and want to do that function with changed variable, when button is pressed,?? because timing in my loop of led (on to off/ off to on ) can be large..
what changes should be done in sketch????

int led = 13;
long ontime;
long offtime;
 int a = 0;
 int b = 0;
 long onsecond = 0;
//  long offsecond = 0;

// the setup routine runs once when you press reset:
void setup() { 

//  long offsecond = 0;
  
  pinMode(led, OUTPUT); 
pinMode(8, INPUT_PULLUP);   //    SKIP BUTTON
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
Serial.begin(9600);

if (digitalRead(8) == LOW)  //   IF BUTTON NOY PRESSED
{
  Serial.println("Setup Running");
  digitalWrite(led, HIGH);   // turn the LED on for 7:53
  delay(473000);  
    digitalWrite(led, LOW); // turn the LED off for 1:07
  delay(67000); 
}
else  
{
  Serial.println("Setup Skipped");
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);  
}

}

void loop() {
long ontime = 1000 + (a*1000);;
long offtime = 1000 + (b*1000);;
long onsecond = (ontime/1000);;
long offsecond = (offtime/1000);
  int Mode = 0; 
 

  
  if (digitalRead(9) == LOW)
  {
   a++;
  }
    if (digitalRead(10) == LOW)
  {
   a--;  
  }
    if (digitalRead(11) == LOW)
  {
   b++; 
  }
    if (digitalRead(12) == LOW)
  {
   b--;
  }
   if  ( ontime<1000)
   {
    ontime = 5000; 
   }
      if  ( offtime<1000)
   {
    offtime = 5000; 
   }
   
   
   Serial.print(onsecond);
   Serial.print("------");
   Serial.print(offsecond);
   Serial.println("     ");
 

 switch (Mode) {
   case 0:
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(ontime);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(offtime);               // wait for a second
  break;
  }
  delay(1);
}

Without being rude, rewrite all your code without any delay() longer than 200mS.
Ideally use millis() throughout.
Until then - any latency issues are not a problem with the code, but with the method of coding.

Hi,
You need to understand that usuig delay(), stops your code for the delay period.

Your LED on/off sequence will stop any initial button response because of it, also as the LED on/off is in the setup() part of your code, nothing in the loop() part can occur until setup() has been completed.

Tom.... :slight_smile:

You need to rewrite your code as a state machine:-
See my
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
Or Robin2's several things at once
http://forum.arduino.cc/index.php?topic=223286.0