class Counter – pulse counter

class machine.Counter(pin, *, edge=Counter.RISING, debounce=0)

Construct a pulse counter object used to count pulses on a pin.

pin is the pin whose pulses are counted. edge is the trigger edge, which can be Counter.RISING (rising edge), Counter.FALLING (falling edge) or Counter.BOTH (both edges). debounce is the debounce time (milliseconds), defaulting to 0.

init(pin, *, edge=Counter.RISING, debounce=0)

Initialize the pulse counter.

The parameters are the same as the constructor.

deinit()

Deinitialize the pulse counter.

value([value])

Get or set the counter value.

If value is provided, the counter value is set. Otherwise, the current counter value is returned.

RISING

Rising-edge trigger.

FALLING

Falling-edge trigger.

BOTH

Both-edge trigger.