countio module contains logic to read and count edge transistions
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
deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
Available on these boards
- class countio.Edge¶
Enumerates which signal transitions can be counted.
Enum-like class to define which signal transitions to count.
- RISE :Edge¶
Count the rising edges.
- FALL :Edge¶
Count the falling edges.
- RISE_AND_FALL :Edge¶
Count the rising and falling edges.
- class countio.Counter(pin: microcontroller.Pin, *, edge: Edge = Edge.FALL, pull: Optional[digitalio.Pull] = None)¶
Count the number of rising- and/or falling-edge transitions on a given pin.
Create a Counter object associated with the given pin that counts rising- and/or falling-edge transitions. At least one of
fallmust be True. The default is to count only falling edges, and is for historical backward compatibility.
import board import countio # Count rising edges only. pin_counter = countio.Counter(board.D1, edge=Edge.RISE) # 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.