unexpected behaviour of digitalPulse

Posted on
  • On a Pico with v1.91 I can do digitalPulse(B3, 1, 0.10, 0.1) to get a short pulse of 0.1ms length, with the pin returning to 0 at the end. I'm expecting the same for digitalPulse(B3, 1, [0.1, 0.1]).
    However, when passing the lengths as array the pin state is finally 1.
    What am I missing here?

  • digitalPulse only takes 3 arguments, so with digitalPulse(B3, 1, 0.10, 0.1) the final argument is ignored - it's like saying digitalPulse(B3, 1, 0.10)

    When you pass an array, you're passing [on,off,on,off,... - so if you pass an odd number of arguments the pin will return to its initial state (in your case 0), but if you pass an even number of arguments it'll finish at 1 - does that help?

  • Definitely, yes. Thanks for the explanation :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

unexpected behaviour of digitalPulse

Posted by Avatar for Steffen @Steffen