Description
This sensor can detect capacitive touch, such as the touch of a finger. It can also be set to display many colors.
The VEX IQ Touch LED Sensor is included in the VEX IQ Super Kit but it can also be purchased here.
How the Touch LED Works: Detecting Touches
The Touch LED uses technology that detects small changes in the physical properties of its surroundings. It does this by measuring capacitance.
Capacitance is a physical property of any object. It can be affected by what a thing is made of, or what it's shaped like. The air around us has a certain capacitance, an electrical circuit has a certain capacitance, and your body has a certain capacitance.
The Touch LED can detect this capacitance by sending an electrical signal and noting what comes back. In the image you can see that when the button is pressed, the purple response signal changes compared to the blue input signal. If the response signal is just right, it means there is a finger present, and the Touch LED sends a message back to the Robot Brain which means that it's being touched.
One advantage of checking for touch in this way is that a change in capacitance does not require that you touch the circuit directly, only that you get very close. As a result, the electronics in the Touch LED can be shielded with plastic and packaged along with more electronics, like the multi-color LEDs inside the device.
Common Uses of the Touch LED:
- This sensor can be used to start or pause a program at the touch of a finger.
- This sensor can be used to display different colors at different parts of a program.
Uses of the Touch LED on a Competition Robot:
- The Touch LED can be used to start a running program with a finger press.
- Team members can see when different sections of an autonomous program are running by programming the Touch LED to display a unique color for each section.
- Using the Touch LED can also be used to help troubleshoot programming problems if issues occur.
Using the Touch LED in VEXcode IQ
Adding the Touch LED as a Device in VEXcode IQ
To code the Touch LED in a VEXcode IQ, you must first configure the Touch LED. View this article to learn more about configuring a sensor in VEXcode IQ.
Once the Touch LED is configured, commands will appear in the Toolbox that you can use in your project.
Coding the Touch LED in Blocks
Pressing Touch LED
The <Pressing Touch LED> block is a Boolean reporter block that reports a condition as either true or false. Boolean blocks, like the <Pressing Touch LED> block fit inside blocks with hexagonal (six-sided) inputs for other blocks.
The <Pressing Touch LED> Boolean block reports 'true' if the Touch LED is pressed, and 'false' if the Touch LED is released or not pressed. To learn more about Boolean blocks visit the Help or the Block Shapes and Meaning article.
Note: The name of the Touch LED that appears in the command corresponds to the name it is given in the configuration.
In this example, the <Pressing Touch LED> block is used with a [Wait until] block to make the robot drive forward for 500mm when the Touch LED is pressed, as shown in the video above.
{When Touch LED}
The <Pressing Touch LED> block is an Event block that will run the stack of blocks attached when the Touch LED is pressed or released.
To learn more about Event blocks visit the Help or the Block Shapes and Meaning article.
In this example, the {When Touch LED} block is used with a [Drive for] block to make the robot drive forward 500 until the Touch LED is pressed, as shown in the video above.
Touch LED Blocks in the Look Category
Each of these blocks can be used to adjust the color shown on the Touch LED.
[Set Touch LED color] is used to set the desired color of the Touch LED.
[Set Touch LED fade] is used to set the desired speed of the fade of the Touch LED to slow, fast, or none.
[Set Touch LED brightness] is used to set the desired brightness level of the Touch LED from 0-100%.
To learn more about each of these blocks visit the Help.
In this example, the Touch LED brightness is set to 100% and the color will first show blue for 2 seconds then slowly fade to red. These blocks can be used to display different colors at different parts of a project.
Coding the Touch LED in Python
Note: To code an VEX IQ (1st generation) Bumper Switch in Python, it must be connected to a VEX IQ (2nd generation) Brain. The VEX IQ (1st generation) Brain does not support Python.
TouchLED.pressing
touchled_3.pressing()
The TouchLED.pressing command reports a Boolean value of either true or false about the Touch LED.
The TouchLED.pressing command reports 'true' if the Touch LED is pressed, and 'false' if the Touch LED is released or not pressed.
Note: The name of the Touch LED that appears in the command corresponds to the name it is given in the configuration.
while True: |
In this example, a While loop with a not condition is used with the TouchLED.pressing command to make the robot drive forward for 500mm when the Touch LED is pressed, as shown in the video above. |
Touch LED Event Commands
touchled_3.pressed(callback)
touchled_3.released(callback)
The TouchLED.pressed and TouchLED.released commands runs a specified callback function when the Touch LED is pressed or released.
def touchled_3_pressed(): |
In this example, the TouchLED.pressed event command is defined as drive_for forward 500mm. The while loop is then used so that any time the Touch LED is pressed, the robot will drive forward for 500mm when the project is run. |
Touch LED Commands in the Looks Category
touchled_3.set_color(Color.BLACK)
touchled_3.set_fade(FadeType.SLOW)
touchled_3.setbrightness(50)
Each of these commands can be used to adjust the color shown on the Touch LED.
Set TouchLED color is used to set the desired color of the Touch LED.
Set TouchLED fade is used to set the desired speed of the fade of the Touch LED to slow, fast, or none.
Set TouchLED brightness is used to set the desired brightness level of the Touch LED from 0-100%.
To learn more about each of these commands visit the Help.
touchled_3.set_brightness(100) |
In this example, the Touch LED brightness is set to 100% and the color will first show blue for 2 seconds then slowly fade to red. These commands can be used to display different colors at different parts of a project. |