Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
37 lines (22 loc) · 884 Bytes

File metadata and controls

37 lines (22 loc) · 884 Bytes
Copy raw file
Download raw file
Outline
Edit and raw actions

class Switch -- switch object

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.callback(f)          # register a callback to be called when the
                        #   switch is pressed down
sw.callback(None)       # remove the callback

Example:

pyb.Switch().callback(lambda: pyb.LED(1).toggle())

Constructors

Create and return a switch object.

Methods

.. method:: switch()

   Return the switch state: ``True`` if pressed down, ``False`` otherwise.

.. method:: switch.callback(fun)

   Register the given function to be called when the switch is pressed down.
   If ``fun`` is ``None``, then it disables the callback.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.