countio
– Support for edge counting¶
The countio
module contains logic to read and count edge transistions
Avertissement
This module is not available in some SAMD21 (aka M0) builds. See the Module Support Matrix - Which Modules Are Available on Which Boards for more info.
All classes change hardware state and should be deinitialized when they
are no longer needed if the program continues after use. To do so, either
call deinit()
or use a context manager. See
Lifetime and ContextManagers for more info.
Available on these boards
- class countio.Counter(pin_a: microcontroller.Pin)¶
Counter will keep track of the number of falling edge transistions (pulses) on a given pin
Create a Counter object associated with the given pin. It tracks the number of falling pulses relative when the object is constructed.
- Paramètres:
pin_a (Pin) – Pin to read pulses from.
For example:
import board import countio pin_counter = countio.Counter(board.D1) #reset the count after 100 counts while True: if pin_counter.count == 100: pin_counter.reset() print(pin_counter.count)
- count :int¶
The current count in terms of pulses.
- __exit__() None ¶
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.