TouchLED#

Initializing the TouchLED Class#

The TouchLED constructor creates a TouchLED object in the specified Smart Port.

This constructor use one parameter:

Parameter

Description

port

A valid Smart Port that the TouchLED Sensor is connected to.

# Construct a TouchLED Sensor "touch" with the
# TouchLED class.
touch = TouchLED(Ports.PORT1)

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

Class Methods#

pressing()#

The pressing() method returns whether the TouchLED Sensor is currently being pressed.

Returns: True if the TouchLED Sensor is currently being pressed. False if it is not.

on()#

The on(value) method turns the LED of the TouchLED Sensor on. Calling with no arguments will turn on the LED with the previously used color. Calling with a color argument will turn the LED on with the specified color.

Parameters

Description

value

A valid ColorType, webstring, or Hexcode value.

Returns: None.

off()#

The off() method turns the LED of the TouchLED Sensor off.

Returns: None.

toggle()#

The toggle() method changes the state of the TouchLED Sensor . If the LED is on it will be turned off, if it is off then it will be turned on.

Returns: None.

set_fade()#

The set_fade(value) method changes the fade setting of the TouchLED Sensor . The TouchLED Sensor will change to new colors using the fade type.

Parameters

Description

value

A valid FadeType.

Returns: None.

set_color()#

The set_color(value) method turns the LED of the TouchLED Sensor on. This has the same functionality as the on() method. Calling with no arguments will turn on the LED with the previously used color. Calling with color arguments will turn the LED on with the specified color.

Parameters

Description

value

A valid ColorType, webstring, or Hexcode value.

Returns: None.

set_brightness()#

The set_brightness(value) method changes the brightness of the TouchLED Sensor . The TouchLED Sensor will be turned on using the previously used color but with a different brightness.

Parameters

Description

value

Brightness in the range of 0 - 255.

Returns: None.

pressed()#

The pressed(callback, arg) method registers a function to be called when the TouchLED Sensor is pressed.

Parameters

Description

callback

A function that will be called when the TouchLED Sensor is pressed.

arg

Optional. A tuple that is used to pass arguments to the callback function.

Returns: An instance of the Event class.

# Define a function touchLED_pressed().
def touchLED_pressed():
    # The Brain will print that the TouchLED Sensor was pressed on 
    # the Brain Screen.
    brain.screen.print("TouchLED Sensor pressed")
# Run touchLED_pressed when the TouchLED Sensor is pressed.
touch.pressed(touchLED_pressed)

released()#

The released(callback, arg) method registers a function to be called when the TouchLED Sensor is released.

This is a non-blocking method and allows the next method to run without delay.

Parameters

Description

callback

A function that will be called when the TouchLED Sensor is released.

arg

Optional. A tuple that is used to pass arguments to the callback function.

Returns: An instance of the Event class.

# Define a function touchLED_released().
def touchLED_released():
    # The Brain will print that the TouchLED Sensor was released on 
    # the Brain Screen.
    brain.screen.print("TouchLED Sensor released")
# Run touchLED_released when the TouchLED Sensor is released.
touch.released(touchLED_released)

installed()#

The installed() method returns if the TouchLED Sensor is connected to the Brain.

Returns: True if the TouchLED Sensor is connected to the Brain. False if it is not.