adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.02k stars 1.19k forks source link

PulseIn pause when full #6580

Open dmcomm opened 2 years ago

dmcomm commented 2 years ago

Currently it overwrites the oldest pulse lengths when full. In many cases, this means the result is invalid and needs to be discarded. For some uses, we could instead get something useful by decoding the beginning of the transmission. So I'm suggesting an option to make it pause when full instead of overwriting.

tannewt commented 7 months ago

I was originally thinking that this was something to blanket change. However, after looking at examples, I see that the behavior as-is is useful if you are trying to sample a PWM signal that varies pulse length. You can set maxlen=2 and read pulse 0 continuously to see how it is varying.

So, you are right that this should be a new kwarg (maybe called pause_on_overflow) that adds in the auto-pause.