• I think you are expecting your setTimeout('pause()', 20); to delay the running of the code for 20 milliseconds.....

    What you have written is basically this:

    
    while (1) {
      digitalWrite(A4, 0);
    
      digitalWrite(B4, 1);
      digitalWrite(B3, 0);
     
      digitalWrite(A4, 1);
      digitalWrite(B4, 0);
     
      digitalWrite(B3, 1);
    }
    

    So it is looping forever toggling the state of the pins. It is also adding new timeouts, faster than they can be executed.

    The timeout calls are a callback. This means that pause() will be called 20 milliseconds later, however the next statement digitalWrite(B4, 1); gets written straight away - it does not wait 20ms before doing that.

    To achieve what you want - you will need to chain calls so that the next action occurs in a call back - not directly.

    I hope this helps.

About

Avatar for Wilberforce @Wilberforce started