aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDamien George2017-06-15 17:34:51 +1000
committerDamien George2017-06-15 17:34:51 +1000
commitfd860dc552b2ec53df8c6ce7e1245206719d469b (patch)
treef0e1fa830f923ebc76d8815c4a30772853696219 /docs
parent4abe3731e3fbce88c2efa265950c5e13b30426d6 (diff)
stmhal: Add .value() method to Switch object, to mirror Pin and Signal.
Diffstat (limited to 'docs')
-rw-r--r--docs/library/pyb.Switch.rst7
-rw-r--r--docs/pyboard/tutorial/switch.rst8
2 files changed, 13 insertions, 2 deletions
diff --git a/docs/library/pyb.Switch.rst b/docs/library/pyb.Switch.rst
index bc62b6eee..0d5dc63b7 100644
--- a/docs/library/pyb.Switch.rst
+++ b/docs/library/pyb.Switch.rst
@@ -8,7 +8,8 @@ A Switch object is used to control a push-button switch.
Usage::
sw = pyb.Switch() # create a switch object
- sw() # get state (True if pressed, False otherwise)
+ sw.value() # get state (True if pressed, False otherwise)
+ sw() # shorthand notation to get the switch state
sw.callback(f) # register a callback to be called when the
# switch is pressed down
sw.callback(None) # remove the callback
@@ -34,6 +35,10 @@ Methods
Call switch object directly to get its state: ``True`` if pressed down,
``False`` otherwise.
+.. method:: Switch.value()
+
+ Get the switch state. Returns `True` if pressed down, otherwise `False`.
+
.. method:: Switch.callback(fun)
Register the given function to be called when the switch is pressed down.
diff --git a/docs/pyboard/tutorial/switch.rst b/docs/pyboard/tutorial/switch.rst
index 945e89aa0..91683fba4 100644
--- a/docs/pyboard/tutorial/switch.rst
+++ b/docs/pyboard/tutorial/switch.rst
@@ -15,12 +15,18 @@ the name ``pyb`` does not exist.
With the switch object you can get its status::
- >>> sw()
+ >>> sw.value()
False
This will print ``False`` if the switch is not held, or ``True`` if it is held.
Try holding the USR switch down while running the above command.
+There is also a shorthand notation to get the switch status, by "calling" the
+switch object::
+
+ >>> sw()
+ False
+
Switch callbacks
----------------