-
-
You must be signed in to change notification settings -
ESP32: New hardware PCNT Counter() and Encoder(). #6639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IhorNehrutsa
wants to merge
153
commits into
micropython:master
Choose a base branch
Loading
Loading
from
IhorNehrutsa:feature/esp32_pcnt_quad
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,160
−1
Changes from all commits
Commits
Show all changes
153 commits
Select commit
Hold shift + click to select a range
c6d6dce
esp32/esp32_pcnt.* : Add files for Pulse counter and Quadrature encoder.
IhorNehrutsa ca67883
esp32/modesp32.*: Add PCNT() & QUAD() to esp32 momdule.
IhorNehrutsa 402438d
Test
IhorNehrutsa dd9e5c1
add
IhorNehrutsa 88ade12
EspError, PCNT, QUAD test Ok
IhorNehrutsa 4965c33
Formatting
IhorNehrutsa 3a29d6a
Formatting
IhorNehrutsa 3f47cfc
ESP32 PCNT QUAD: Add documentation and hide some methods and consts.
IhorNehrutsa a7386a3
ESP32 PCNT QUAD: Fix documentation and delete duplicates in code.
IhorNehrutsa 3deaa23
ESP32 PCNT QUAD: Formatting
IhorNehrutsa fb1a533
ESP32 PCNT QUAD: Formatting
IhorNehrutsa d12c849
esp32/esp32_pcnt.c: Use ESP_EXCEPTIONS() macro.
IhorNehrutsa c9501e8
Merge branch 'master' into feature/esp32_pcnt_quad
IhorNehrutsa d7bd201
revert gitignore
IhorNehrutsa 305ebe3
Remove esp_error.c and esp_error.h
IhorNehrutsa 1c5cabf
Revert EspError
IhorNehrutsa e9214ad
Remove EspError
IhorNehrutsa 2fcc1ab
Update esp32.rst
IhorNehrutsa 93cad4b
Update CMakeLists.txt
IhorNehrutsa fe7872a
Update CMakeLists.txt
IhorNehrutsa 747fd92
Update esp32_pcnt.c
IhorNehrutsa caa1fac
docs: 64-bit signed counter value
IhorNehrutsa 24b06bf
Del PinPull
IhorNehrutsa c2789db
Del pull
IhorNehrutsa 7556444
Pin expected
IhorNehrutsa 47abe7a
Update mpprint.h
IhorNehrutsa ab726fc
py/obj: Add func to get int64 arguments
IhorNehrutsa d29ed14
Merge pull request #4 from IhorNehrutsa/esp32_pcnt_quad_delete_PinPull
IhorNehrutsa 3912a1c
Remove class:: pcnt.PinPull()
IhorNehrutsa 35646e7
Renames
IhorNehrutsa 1f11157
Renames
IhorNehrutsa f4bf625
Revert mp_const_obj_t to mp_obj_t
IhorNehrutsa 540894d
Update pcnt.rst
IhorNehrutsa fa8aa57
wip
IhorNehrutsa 3d7b8e0
move to machine
IhorNehrutsa cefa67b
Update esp32_pcnt.c
IhorNehrutsa
8000
Oct 10, 2021
6e994b1
wip
IhorNehrutsa eb5b53f
docs
IhorNehrutsa 951d34b
wip
IhorNehrutsa af61d97
Merge branch 'feature/esp32_pcnt_quad' of https://github.com/IhorNehr…
IhorNehrutsa b4c37e7
wip docs
IhorNehrutsa 8e3ca2b
move pcnt.rst to esp32
IhorNehrutsa 17cfaf7
docs
IhorNehrutsa da87088
docs
IhorNehrutsa 619e353
Update general.rst
IhorNehrutsa dcf8fa1
Update machine.Encoder.rst
IhorNehrutsa 8f83af3
Remove set_value()
IhorNehrutsa 48766b8
Revert "Remove set_value()"
IhorNehrutsa da5f2ea
wip
IhorNehrutsa 4a3b043
Update esp32_pcnt.c
IhorNehrutsa 5f66d83
Update pcnt.rst
IhorNehrutsa e994345
esp32/machine_pwm: Add PWM duty_u16() and duty_ns().
IhorNehrutsa 87e9278
esp32/machine_pwm.c: Fix Changing the PWM frequency affects the duty …
IhorNehrutsa 3bf8dff
docs/machine.PWM.rst: Add notes about frequency, duty and resolution.
IhorNehrutsa d9da9e5
esp32/machine_pwm.c Add support ESP32 S2, S3, C3.
IhorNehrutsa 880ff57
esp32/machine.pwm: Fix rounding in resolution calculation.
IhorNehrutsa dec63ab
esp32\machine_pwm.c: Fix code formatting.
IhorNehrutsa 4dfdc99
Merge branch 'master' of https://github.com/IhorNehrutsa/micropython
IhorNehrutsa d083596
esp32/esp32_pcnt.* : Add files for Pulse counter and Quadrature encoder.
IhorNehrutsa a5dddd4
esp32\mpconfigport.h: Revert after rebase.
IhorNehrutsa 9155b59
py/mpprint.h: Add DBG() macro.
IhorNehrutsa 1d650f2
Merge branch 'micropython:master' into master
IhorNehrutsa b6d9183
py/mprint.h: Change names to MP_PRN & MP_PRN_LEVEL.
IhorNehrutsa bc321a6
Merge branch 'master' of https://github.com/micropython/micropython i…
IhorNehrutsa 136cb2e
Merge branch 'micropython-master' into master
IhorNehrutsa 73456a1
esp32/esp32_pcnt.* : Add files for Pulse counter and Quadrature encoder.
IhorNehrutsa d60e562
esp32\mpconfigport.h: Revert after rebase.
IhorNehrutsa ef76b1f
Merge branch 'feature/esp32_pcnt_quad' of https://github.com/IhorNehr…
IhorNehrutsa f933fe9
Merge branch 'feature/esp32_pcnt_quad' of https://github.com/IhorNehr…
IhorNehrutsa 2c471df
Update modesp32.c
IhorNehrutsa d05fc5c
Merge branch 'feature/esp32_pcnt_quad' of https://github.com/IhorNehr…
IhorNehrutsa d792e74
wip
IhorNehrutsa 2d13bd3
Update index.rst
IhorNehrutsa 666c4a2
fixes
IhorNehrutsa e1884e3
Update esp32_pcnt.c
IhorNehrutsa c36241d
esp32/esp32_pcnt.c: Remove unused functions.
IhorNehrutsa ce6e012
esp32\esp32_pcnt.*: Rename RAISE/FALL to RISING/FALLING.
IhorNehrutsa 479dea2
esp32: Use 4 as default for x124.
IhorNehrutsa e1df144
Update esp32_pcnt.c
IhorNehrutsa c92cd69
esp32/esp32_pcnt.c: Add get_value().
IhorNehrutsa 5fd5a3d
Update esp32_pcnt.c
IhorNehrutsa f9a1cea
esp32\PCNT: Correct docs.
IhorNehrutsa 1e6e5d9
docs/machine: Remove Counter and Encoder.
IhorNehrutsa 43dade5
esp32\machine_pwm.c: HOTFIX PWM duty.
IhorNehrutsa 9a46918
py\mpprint.h: Change MP_PRN() delimiter to '|'.
IhorNehrutsa 584fd31
Merge branch 'DBG_macro' into HOTFIX_esp32_PWM_duty
IhorNehrutsa 5d79d19
Update pcnt.rst
IhorNehrutsa 951c2ad
FILTER_MAX
IhorNehrutsa fa831de
Merge branch 'DBG_macro' into feature/esp32_pcnt_quad
IhorNehrutsa 200dc6f
Merge remote-tracking branch 'origin/HOTFIX_esp32_PWM_duty' into feat…
IhorNehrutsa f111b1e
Update esp32_pcnt.c
IhorNehrutsa 1aea642
esp32/PCNT: Constructor & init.
IhorNehrutsa 23e74bd
Revert "Merge branch 'DBG_macro' into HOTFIX_esp32_PWM_duty"
IhorNehrutsa e9d0853
esp32/esp32_pcnt.c: Remove MP_PRN() macro.
IhorNehrutsa 6c89fcc
esp32\Encoder: Rename esp32_pcnt to machine_encoder.
IhorNehrutsa b0321dc
Revert "Merge remote-tracking branch 'origin/HOTFIX_esp32_PWM_duty' i…
IhorNehrutsa 2d5ffb6
esp32\pcnt: Revert after revert.
IhorNehrutsa 56243c5
esp32/pcnt: Revert after revert.
IhorNehrutsa 6492051
Update machine_pwm.c
IhorNehrutsa 9b838a6
esp32\PCNT: ESP32 ESP32S2 ESP32S3 supported only.
IhorNehrutsa b5ec1c4
docs\esp32\PCNT: Change ref pcnt.Counter to esp32_machine.Counter.
IhorNehrutsa e9c7ac0
Update intro.rst
IhorNehrutsa 64db6c3
Revert mpprint.h
IhorNehrutsa 1bd26f8
Revert machine_pwm.c
IhorNehrutsa 67dc2f3
Revert machine.rst
IhorNehrutsa 6ef5ea3
esp32/Encoder: Fix GENERIC_C3 board.
IhorNehrutsa ccdde48
esp32/Encoder: Fix GENERIC_S3 board.
IhorNehrutsa 9a7a8f1
Update quickref.rst
IhorNehrutsa af3d02d
Update machine_encoder.c
IhorNehrutsa ad1cf37
esp32/machine_encoder.c: Fix PCNT_UNIT_MAX.
IhorNehrutsa 2c18c7a
esp32/encoder: WIP.
IhorNehrutsa 5bbe52e
WIP
IhorNehrutsa 5bd4a0b
WIP
IhorNehrutsa 3e97b04
WIP
IhorNehrutsa 5f92b4c
esp32/machine_encoder: Formatting.
IhorNehrutsa 5056b9c
py/obj: Revert.
IhorNehrutsa 4252a1d
Update machine_encoder.c
IhorNehrutsa 79fab54
Update machine_encoder.c
IhorNehrutsa b3ef33e
Update machine_encoder.c
IhorNehrutsa 4021243
Update pcnt.rst
IhorNehrutsa e1b9f1e
Add COUNTER_UP, COUNTER_DOWN
IhorNehrutsa 4878e8f
WIP
IhorNehrutsa aa4b7a1
WIP
IhorNehrutsa dc011f7
Update pcnt.rst
IhorNehrutsa 3be5036
esp32/machine_encoder.c: Fix RIZING, FALLING, counter_clear().
IhorNehrutsa 132bc7d
esp32/machine_encoder: Constants as bitmap.
IhorNehrutsa 39d51ab
esp32/machine_encoder: Fix ESP-IDF events _EVT_ const.
IhorNehrutsa 0e6f8d1
Update machine_encoder.c
IhorNehrutsa 26b3000
esp32/Encoder: Fix Soft Reset macine_encoder_deinit_all() for ESP-IDF…
IhorNehrutsa 4bba75d
Update machine_encoder.c
IhorNehrutsa b1e6796
Update machine_encoder.c
IhorNehrutsa fe7ebef
WIP
IhorNehrutsa f1d8e37
WIP
IhorNehrutsa 5c70097
Update machine_encoder.c
IhorNehrutsa a6cd7b9
Update pcnt.rst
IhorNehrutsa 7e401ea
esp32/machine_encoder.c: Add pin_or_int() function.
IhorNehrutsa 65106e6
Update machine_encoder.c
IhorNehrutsa 8863da7
Update machine_encoder.h
IhorNehrutsa 2ca2966
Update machine_encoder.c
IhorNehrutsa c166227
esp32/machine_encoder.c: irq(handler=None, trigger=Counter.IRQ_MATCH1…
IhorNehrutsa d332e20
esp32/machine_encoder.c: Fix A-B phase sequence.
IhorNehrutsa 9f0e4a8
docs\esp32\pcnt.rst: irq(handler=None, trigger=Counter.IRQ_MATCH1 | C…
IhorNehrutsa dcbd120
esp32/machine_encoder: Make sure channel 1 is not set.
IhorNehrutsa de94ced
Update machine_encoder.c
IhorNehrutsa a7741b6
esp32/machine_encoder.c: Fix irq() method.
IhorNehrutsa f50055a
Update pcnt.rst
IhorNehrutsa 563ab51
Update general.rst
IhorNehrutsa ee75e0d
Update general.rst
IhorNehrutsa 50dfed8
Merge branch 'feature/esp32_pcnt_quad' of https://github.com/IhorNehr…
IhorNehrutsa a190c01
Merge branch 'master' into feature/esp32_pcnt_quad
IhorNehrutsa 8cd53a2
Update pcnt.rst
IhorNehrutsa 92bee8e
Update pcnt.rst
IhorNehrutsa 3600c7f
Update pcnt.rst
IhorNehrutsa File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<
A3DB
/div>
View file
Open in desktop
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
PCNT - Counter and Encoder | ||
========================== | ||
|
||
The Counter and Encoder use the ESP32 Pulse Counter (PCNT) hardware peripheral, | ||
see Espressif's `ESP-IDF Pulse Counter documentation. | ||
<https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/pcnt.html>`_ | ||
|
||
For the counter not to miss any pulses, the pulse duration should be longer than one ESP32 APB_CLK cycle (1 / 80 MHz = 12.5 ns). | ||
The pulses are sampled on the edges of the APB_CLK clock and may be missed if fall between the edges. | ||
With ideal input signal maximum frequency of measured pulses is APB_CLK / 2 = 80 MHz / 2 = 40 MHz. | ||
|
||
The inputs have optional filters that can be used to discard unwanted glitches in the signal. | ||
The length of ignored pulses is provided in APB_CLK clock cycles. | ||
* Note: Filter value is a 10-bit value, so the maximum filter value should be limited to 1023. | ||
Maximum filtered glitches delay is 1023 * 12.5 ns = 12.7875 us. | ||
Big filter make cutbacks the input frequency: 1 / (12.7875 us * 2) = 39.1 kHz. | ||
* Note: Do not neglect circuitry methods to reduce noise (right powering and grounding, filtering, shielding, | ||
short conductors, twisted pair cable, differential signals, etc.). | ||
|
||
There is only one interrupt for the peripheral, and that is managed inside the module. | ||
The user has no interrupt interface, and no interrupts are generated on each pulse. | ||
Interrupts arrive when the 16-bit hardware counter buffer overflows, so this module has a tiny interrupt footprint | ||
while providing support for up to 8 simultaneous counters (Encoder or Counter objects). | ||
|
||
.. _esp32_machine.Counter: | ||
|
||
Counter | ||
======= | ||
|
||
The Pulse Counter service. | ||
|
||
Constructor | ||
----------- | ||
|
||
.. class:: Counter(id, src=None, \*, edge=Counter.RISING, direction=Counter.UP, filter_ns=0, scale=1) | ||
|
||
The Counter starts to count immediately. Filtering is disabled. | ||
|
||
- *id*. Values of *id* depend on a particular port and its hardware. | ||
Values 0, 1, etc. are commonly used to select hardware block #0, #1, etc. | ||
|
||
- *src* is the pulse input :ref:`machine.Pin <machine.Pin>` to be monitored. | ||
*src* is required in the constructor. | ||
|
||
- *direction* specifies the direction to count. Values for this include the constants | ||
|
||
- Counter.UP - (default value) and | ||
- Counter.DOWN to control the direction by software or | ||
- :ref:`machine.Pin <machine.Pin>` object to control the direction externally. If ``Pin.value()``: | ||
- 0 - count down, | ||
- 1 - count up. | ||
|
||
- *edge* specifies which edges of the input signal will be counted by Counter: | ||
|
||
- Counter.RISING : raise edges, | ||
- Counter.FALLING : fall edges, | ||
- Counter.RISING | Counter.FALLING : both edges. | ||
|
||
- *filter_ns* specifies a ns-value for the minimal time a signal has to be stable | ||
at the input to be recognized. The largest value is 12787ns (1023 * 1000000000 / APB_CLK_FREQ). | ||
The default is 0 – no filter. | ||
|
||
- *scale* sets the scale value. The default value is 1. You may treat the scale | ||
factor as **click per count**, **mm pe F438 r count**, **inch per count** etc. | ||
|
||
Methods | ||
------- | ||
|
||
.. method:: Counter.init(*, src, ...) | ||
|
||
Modify the settings of the Counter object. See the **Constructor** for details about the parameters. | ||
|
||
.. method:: Counter.deinit() | ||
|
||
Stops the Counter, disables interrupts and releases hardware resources used by the counter. | ||
A Soft Reset involve deinitializing all Encoder objects. | ||
|
||
.. method:: Counter.filter([value]) | ||
|
||
Get, and optionally set, the filter value. 0 disable filtering. | ||
|
||
.. method:: Counter.value([value]) | ||
|
||
Get, and optionally set, the counter *value* as a signed 64-bit integer. | ||
|
||
.. method:: Counter.scaled([value]) | ||
|
||
Get, and optionally set, the current scaled value of the Counter as a float. | ||
|
||
Pseudocode is:: | ||
|
||
def scaled(self, scaled=None): | ||
_scaled = self._value * self.scale | ||
if scaled is not None: | ||
self._value = round(scaled / self.scale) | ||
return _scaled | ||
|
||
.. method:: Counter.irq(handler=None, trigger=Counter.IRQ_MATCH1 | Counter.IRQ_MATCH2 | Counter.IRQ_ZERO, value=0) | ||
|
||
-*handler* specifies a function is called when the respective *trigger* event happens. | ||
The callback function *handler* receives a single argument, which is the Counter object. | ||
All events may share the same callback or have separate callbacks. | ||
The callback will be disabled, when called with handler=None. Counter.irq() disable all callbacks. | ||
The event which triggers the callback can be identified with the ``Counter.status()`` method. | ||
The Counter object which triggers the callback can be identified with the ``Counter.id()`` method. | ||
|
||
-*trigger* events may be: | ||
|
||
- Counter.IRQ_MATCH1 triggered when the counter matches the match1 value. | ||
- Counter.IRQ_MATCH2 triggered when the counter matches the match2 value. | ||
- Counter.IRQ_ZERO triggered when the counter matches the 0. | ||
|
||
The default is - trigger=Counter.IRQ_MATCH1 | Counter.IRQ_MATCH2 | Counter.IRQ_ZERO. | ||
The events are triggered when the counter value and match value are identical, but | ||
callbacks have always a latency. | ||
|
||
- *value* sets a counter match1/match2 value. When the counter matches these values, | ||
a callback function can be called. They are 0 by default. | ||
|
||
Attention: ``Counter.irq()`` resets counter to 0. | ||
|
||
.. method:: Counter.status() | ||
|
||
Returns the event status flags of the recent handled Counter interrupt as a bitmap. | ||
|
||
.. method:: Counter.id() | ||
|
||
Returns id number. | ||
|
||
.. method:: Counter.pause() | ||
|
||
.. method:: Counter.resume() | ||
|
||
Constants | ||
--------- | ||
|
||
.. data:: Counter.UP | ||
Counter.DOWN | ||
|
||
Selects the counter direction. | ||
|
||
.. data:: Counter.RISING | ||
Counter.FALLING | ||
|
||
Selects the counted edges. | ||
|
||
.. data:: Counter.IRQ_MATCH1 | ||
Counter.IRQ_MATCH2 | ||
Counter.IRQ_ZERO | ||
|
||
Selects callback triggers. | ||
|
||
:: | ||
|
||
from machine import Counter, Pin | ||
|
||
try: | ||
def irq_handler(self): | ||
print('irq_handler()', self.id(), self.status(), self.value()) | ||
|
||
cnt = Counter(0, src=Pin(17, mode=Pin.IN), direction=Pin(16, mode=Pin.IN)) | ||
|
||
cnt.pause() | ||
flt = cnt.filter() # return current filter value. | ||
cnt.filter(10_000) # filter delay is 10ms | ||
c = cnt.value(0) # get current counter value, set the counter value to 0 | ||
cnt.irq(irq_handler, Counter.IRQ_ZERO) # set irq handler | ||
cnt.resume() | ||
|
||
_c = None | ||
while True: | ||
c = cnt.value() # get the counter value | ||
if _c != c: | ||
_c = c | ||
print('Counter =', c) | ||
finally: | ||
cnt.deinit 10000 () # free the input pins and counter. | ||
|
||
|
||
.. _esp32_machine.Encoder: | ||
|
||
Encoder | ||
======= | ||
|
||
This class provides a Quadrature Incremental Encoder service. | ||
See `Quadrature encoder outputs. | ||
<https://en.wikipedia.org/wiki/Incremental_encoder#Quadrature_outputs>`_ | ||
|
||
.. image:: img/quad.png | ||
:width: 397px | ||
|
||
Constructor | ||
----------- | ||
|
||
.. class:: Encoder(id, phase_a=None, phase_b=None, \*, x124=4, filter_ns=0, scale=1, match1=0, match2=0) | ||
|
||
The Encoder starts to count immediately. Filtering is disabled. | ||
|
||
- *id*. Values of *id* depend on a particular port and its hardware. | ||
Values 0, 1, etc. are commonly used to select hardware block #0, #1, etc. | ||
|
||
- *phase_a*, *phase_b* are input pins :ref:`machine.Pin <machine.Pin>` for monitoring of quadrature encoder pulses. | ||
They are required in the constructor. | ||
|
||
- *x124* is a hardware multiplier, possible values is 1, 2, 4. The default value is 4. | ||
More info in `Quadrature decoder state table <https://en.wikipedia.org/wiki/Incremental_encoder#Quadrature_decoder>`_. | ||
When more Encoder resolution is needed, it is possible for the encoder to count the leading | ||
and trailing edges of the quadrature encoder’s pulse train from one channel, | ||
which doubles (x2) the number of pulses. Counting both leading and trailing edges | ||
of both channels (A and B channels) of a quadrature encoder will quadruple (x4) the number of pulses: | ||
|
||
- 1 - count the leading(or trailing) edges from one phase channel. | ||
- 2 - count the leading and trailing edges from one phase channel. | ||
- 4 - count both leading and trailing edges of both phase channels. | ||
|
||
- *scale* sets the scale value. The default value is 1. You may treat the scale | ||
factor as **click per impulse**, **revolution per impulse**, **angle per impulse** etc. | ||
Hint: Set scale factor to 1/4 to balance the multiplier x124=4. | ||
|
||
These keywords are the same as the Counter keywords, see above: | ||
- *filter_ns* | ||
- *match1* | ||
- *match2* | ||
|
||
Methods | ||
------- | ||
|
||
.. method:: Encoder.init(*, phase_a, ...) | ||
|
||
Modify the settings of the Encoder object. See the **Constructor** for details about the parameters. | ||
|
||
The Encoder has the same methods as the Counter and differs only | ||
in the constructor and internal hardware PCNT initialization. | ||
|
||
Constants | ||
--------- | ||
|
||
.. data:: Encoder.IRQ_MATCH1 | ||
Encoder.IRQ_MATCH2 | ||
Encoder.IRQ_ZERO | ||
|
||
Selects callback triggers. | ||
|
||
:: | ||
|
||
from machine import Encoder, Pin | ||
|
||
try: | ||
n = 0 | ||
def irq_handler1(self): | ||
n -= 1 | ||
print('irq_handler1()', self.id(), self.value(), n) | ||
|
||
def irq_handler2(self): | ||
n += 1 | ||
print('irq_handler2()', self.id(), self.value(), n) | ||
|
||
enc = Encoder(0, phase_a=Pin(17, mode=Pin.IN), phase_b=Pin(16, mode=Pin.IN), match1=-1000, match2=1000) | ||
|
||
enc.pause() | ||
flt = enc.filter() # return current filter value. | ||
enc.filter(10_000) # filter delay is 10ms | ||
c = enc.value(0) # get current encoder value, set the encoder value to 0 | ||
enc.irq(irq_handler1, Encoder.IRQ_MATCH1) # set irq handler | ||
enc.irq(irq_handler2, Encoder.IRQ_MATCH2) # set irq handler | ||
enc.resume() | ||
|
||
_c = None | ||
while True: | ||
c = enc.value() # get the encoder value | ||
if _c != c: | ||
_c = c | ||
print('Encoder =', c) | ||
finally: | ||
enc.deinit() # free the input pins and encoder. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ to `<https://www.python.org>`__. | |
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:numbered: | ||
|
||
intro.rst | ||
pwm.rst | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a mistake. Numbering is not required here.