Limit#

Initializing the Limit Class#

A Limit Switch is created by using the following constructor:

Limit(port)

This constructor uses one parameter:

Parameter

Description

port

The 3-Wire Port that the Limit Switch is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Limit Class constructor.

# Create the Brain.
brain = Brain()
# Construct a Limit Switch "limit" with the Limit class.
limit = Limit(brain.three_wire_port.a)

This limit object will be used in all subsequent examples throughout this API documentation when referring to Limit class methods.

Class Methods#

pressed()#

The pressed(callback, arg) method registers a callback function for when the Limit Switch is pressed.

Parameters

Description

callback

The callback function to be called when the Limit Switch is pressed.

arg

Optional. A tuple of arguments to pass to the callback function.

Returns: None.

# Define a function switch_pressed().
def switch_pressed():
    # The Brain will print that the Limit Switch was pressed 
    # on the Brain's screen.
    brain.screen.print("switch pressed")
# Run switch_pressed when the Limit Switch is pressed.
limit.pressed(switch_pressed)

released()#

The released(callback, arg) method registers a callback function for when the Limit Switch is released.

Parameters

Description

callback

The callback function to be called when the Limit Switch is released.

arg

Optional. A tuple of arguments to pass to the callback function.

Returns: None.

# Define a function switch_released().
def switch_released():
    # The Brain will print that the Limit Switch was released
    # on the Brain's screen.
    brain.screen.print("switch released") 
# Run switch_released when the Limit Switch is released.
limit.released(switch_released)

pressing()#

The pressing() method checks if the Limit Switch is currently being pressed.

Returns: True if the Limit Switch is currently being pressed. False if it is not.