From 641ca2eb0624fc0df2b358f1a4652525af123fd7 Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Mon, 12 Sep 2022 18:37:22 +0100 Subject: docs/library/machine: Add docs for Counter and Encoder. Add documentation for `machine.Counter` and `machine.Encoder` as currently implemented by the esp32 port, but intended to be implemented by other ports. Originally authored by: Ihor Nehrutsa and Jonathan Hogg . Signed-off-by: Jim Mussared --- docs/esp32/quickref.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'docs/esp32') diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index 7127cc402..2c667a0f0 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -587,6 +587,21 @@ Use the :ref:`esp32.PCNT ` class:: The PCNT hardware supports monitoring multiple pins in a single unit to implement quadrature decoding or up/down signal counters. +See the :ref:`machine.Counter ` and +:ref:`machine.Encoder ` classes for simpler abstractions of +common pulse counting applications:: + + from machine import Pin, Counter + + counter = Counter(0, Pin(2)) # create a counter as above and start it + count = counter.value() # read the count as an arbitrary precision signed integer + + encoder = Encoder(0, Pin(12), Pin(14)) # create an encoder and begin counting + count = encoder.value() # read the count as an arbitrary precision signed integer + +Note that the id passed to these ``Counter()`` and ``Encoder()`` objects must be +a PCNT id. + Software SPI bus ---------------- -- cgit v1.2.3