Help exiting delay()


Split from an unrelated topic

@alinkarl - please look at Read this before posting a programming question and edit your post to use code tags



The answer to your problem is, of course, don’t use delay.


Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

//im newbie, i want help to my program, if there is interrupt
between the delay it will not perform the condition and the
output pin will blink once only thanks guy for understanding...

In programming the word "interrupt" has a very specific technical meaning and I can see sign of any use of interrupts in your program.

If you want a responsive program you should not use delay() as the Arduino is blocked until the delay() completes. And for the same reason don't use WHILE or FOR unless they complete very quickly - in a small number of microseconds. Generally it is better to use IF and allow loop() to do the repetition.

Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.


int sw1 = 2;
int sw2 = 3;
int sw3 = 4;
if ((sw1 == 0) && (sw2 == 0) && (sw3 == 1)){

So basically, you are testing this after substituting those values:

if ((2 == 0) && (3 == 0) && (4 == 1)){

This will fix your switch reads:

void loop() {

  int sw1State = digitalRead(sw1);
  int sw2State = digitalRead(sw2);
  int sw3State = digitalRead(sw3);

  if ((sw1State == LOW) && (sw2State == LOW) && (sw3State == HIGH)) {

But, as others have stated, you might want to use millis() as an alternative to delay(). Also, I don't think some of your conditionals work as you expect. Auto-format your code and you'll see why.