• Pulse the pin with the value for the given time in milliseconds. It uses a hardware timer to produce accurate pulses, and returns immediately (before the pulse has finished). Use digitalPulse(A0,1,0) to wait until a previous pulse has finished. [...digitalPulse() reference]

    The immediate return mays cause your problem: 'things' start to overlap. I do not know how exactly your code works, most of the time this asynchronousity things - in this case ending the pulse(s) -happens while continuing code already executes (when the pulse(s) are not extremely short - which means, that the code execution is so much slower that the pulse completed before return processing and going on to the next statement happens). Therefore, 1st, all pulses should be in one array, and after firing it, one has to wait for the time the pulses - all ons and offs - together take to complete. Since 'waiting in Espruino' has to be with setTimeout(...), it is asynchronous and you have to work with callbacks: your pulses function has to accept a callback as parameter in addition to the pulse array which you invoke after firing off the pulses array in a setTimeout(...).


Avatar for allObjects @allObjects started