-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
countio enhancements #5606
Comments
Great enhancements. |
@dhalbert Just read through your comments on #5803 there. It looks like it will be quite useful, thank you! I'm curious, as I bounce between micropython and circuitpython for a project here due to differing demands, is there a way to tell how much time has elapsed in a pin state? In the mentioned project I have a relatively slow speed serial protocol that depends on high pulse duration to determine 0/1 (0.8ms vs 1.2ms, with reset as high > 2ms OR low > 0.4ms). I've been able to decode it cleanly with 'flipping' interrupts in micropython, discerning values at > 2ms, > 1ms, and > .2 ms high and > 3ms low, through the use of utime.ticks_us() but I'd prefer to handle everything in circuitpython as the rest of my code is much cleaner and able to rely on existing libraries. |
@tonsofpcs For that, you may want to try |
Fixed by #5803. |
Really excited about this functionality--- I am working my way through https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio/handling-interrupts right now. Is it possible to extend the functionality to read from the pin within the Counter context? I have a https://www.adafruit.com/product/3218 toggle switch connected to an M4, with the switch pins connecting a 3.3V and the input pin on the board. I want an interrupt to behave differently based on whether the switch transition to ON or OFF. But I don't seen an obvious way to read the state of the pin. I think the guide could really benefit from 1 more complicated example that uses |
@felker However, toggle switch (or any mechanical switch) is going to bounce. Instead of using |
@dhalbert that is actually great to hear, since I switched to I observed debounce with Is that how I would lengthen the polling interval in the It would be great to add a paragraph or example to that interrupt guide encapsulating the info in your comment. |
The
Will do -- thanks for the suggestion! |
countio.Counter
was originally added to handle rotary encoders, but it can also be used as a general-purpose pin-interrupt detector. However, it could use some more functionality.Counter
only counts falling edges. Generalize it to handle rising edges, and also transitions in either direction.Provide an atomic fetch-and-clear operation, to avoid losing any counts.Some implementations use PWM instead of interrupts. It's not clear we can do this atomically cleanly.Add anThis is not really necessary: polling works, and maybe eventually we will add triggering anasync
method so you canawait
changes in the count.asyncio.Event
.The text was updated successfully, but these errors were encountered: