diff options
author | Jonathan Hogg <me@jonathanhogg.com> | 2022-09-12 18:37:22 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-08-02 00:00:03 +1000 |
commit | 641ca2eb0624fc0df2b358f1a4652525af123fd7 (patch) | |
tree | 42d2585a96a49aeeece189b3d10824414dfcd632 /docs/esp32 | |
parent | 327655905e9f523070301f2f35459197d46db4fb (diff) |
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 <Ihor.Nehrutsa@gmail.com> and
Jonathan Hogg <me@jonathanhogg.com>.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'docs/esp32')
-rw-r--r-- | docs/esp32/quickref.rst | 15 |
1 files changed, 15 insertions, 0 deletions
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 <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 <machine.Counter>` and +:ref:`machine.Encoder <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 ---------------- |