Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
bc0bc764
Commit
bc0bc764
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
docs: Add debounce tutorial; order Pin methods; add pull resistor info.
parent
183ac71d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/library/pyb.Pin.rst
+31
-28
31 additions, 28 deletions
docs/library/pyb.Pin.rst
docs/tutorial/debounce.rst
+37
-0
37 additions, 0 deletions
docs/tutorial/debounce.rst
docs/tutorial/index.rst
+1
-0
1 addition, 0 deletions
docs/tutorial/index.rst
with
69 additions
and
28 deletions
docs/library/pyb.Pin.rst
+
31
−
28
View file @
bc0bc764
...
...
@@ -55,6 +55,9 @@ an ordinal pin number:
You can set ``pyb.Pin.debug(True)`` to get some debug information about
how a particular object gets mapped to a pin.
When a pin has the ``Pin.PULL_UP`` or ``Pin.PULL_DOWN`` pull-mode enabled,
that pin has an effective 40k Ohm resistor pulling it to 3V3 or GND
respectively (except pin Y5 which has 11k Ohm resistors).
Constructors
------------
...
...
@@ -62,7 +65,7 @@ Constructors
.. class:: pyb.Pin(id, ...)
Create a new Pin object associated with the id. If additional arguments are given,
they are used to initialise the pin. See
``
init`
`
.
they are used to initialise the pin. See
:meth:`pin.
init`.
Class methods
...
...
@@ -88,24 +91,6 @@ Class methods
Methods
-------
.. method:: pin.__str__()
Return a string describing the pin object.
.. method:: pin.af()
Returns the currently configured alternate-function of the pin. The
integer returned will match one of the allowed constants for the af
argument to the init function.
.. method:: pin.gpio()
Returns the base address of the GPIO block associated with this pin.
.. method:: pin.high()
Set the pin to a high logic level.
.. method:: pin.init(mode, pull=Pin.PULL_NONE, af=-1)
Initialise the pin:
...
...
@@ -126,10 +111,37 @@ Methods
Returns: ``None``.
.. method:: pin.high()
Set the pin to a high logic level.
.. method:: pin.low()
Set the pin to a low logic level.
.. method:: pin.value([value])
Get or set the digital logic level of the pin:
- With no argument, return 0 or 1 depending on the logic level of the pin.
- With ``value`` given, set the logic level of the pin. ``value`` can be
anything that converts to a boolean. If it converts to ``True``, the pin
is set high, otherwise it is set low.
.. method:: pin.__str__()
Return a string describing the pin object.
.. method:: pin.af()
Returns the currently configured alternate-function of the pin. The
integer returned will match one of the allowed constants for the af
argument to the init function.
.. method:: pin.gpio()
Returns the base address of the GPIO block associated with this pin.
.. method:: pin.mode()
Returns the currently configured mode of the pin. The integer returned
...
...
@@ -158,15 +170,6 @@ Methods
will match one of the allowed constants for the pull argument to the init
function.
.. method:: pin.value([value])
Get or set the digital logic level of the pin:
- With no argument, return 0 or 1 depending on the logic level of the pin.
- With ``value`` given, set the logic level of the pin. ``value`` can be
anything that converts to a boolean. If it converts to ``True``, the pin
is set high, otherwise it is set low.
Constants
---------
...
...
This diff is collapsed.
Click to expand it.
docs/tutorial/debounce.rst
0 → 100644
+
37
−
0
View file @
bc0bc764
Debouncing a pin input
======================
A pin used as input from a switch or other mechanical device can have a lot
of noise on it, rapidly changing from low to high when the switch is first
pressed or released. This noise can be eliminated using a capacitor (a
debouncing circuit). It can also be eliminated using a simple function that
makes sure the value on the pin is stable.
The following function does just this. It gets the current value of the given
pin, and then waits for the value to change. The new pin value must be stable
for a continuous 20ms for it to register the change. You can adjust this time
(to say 50ms) if you still have noise. ::
import pyb
def wait_pin_change(pin):
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
while active < 20:
if pin.value() != cur_value:
active += 1
else:
active = 0
pyb.delay(1)
Use it something like this::
import pyb
pin_x1 = pyb.Pin('X1', pyb.Pin.IN, pyb.Pin.PULL_DOWN)
while True:
wait_pin_change(pin_x1)
pyb.LED(4).toggle()
This diff is collapsed.
Click to expand it.
docs/tutorial/index.rst
+
1
−
0
View file @
bc0bc764
...
...
@@ -43,4 +43,5 @@ Tips, tricks and useful things to know
:maxdepth: 1
:numbered:
debounce.rst
pass_through.rst
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment