LED Bumper#
Introduction#
The LED Bumper can change the color of its LED and detect when it is pressed.
For the examples below, the configured LED Bumper will be named bumper
. They will be used in all subsequent examples throughout this API documentation when referring to LEDBumper
class methods.
Below is a list of all methods:
Mutators – Change colors and brightness.
set_color
– Set the color of the LED Bumper.set_brightness
– Set the brightness of the LED Bumper.
Getters – Return data from the LED Bumper.
is_pressed
– Returns whether or not the LED Bumper is being pressed.
Mutators#
set_color#
set_color
sets the color of the LED Bumper. If the LED is not already on when this method is used, it will set the brightness to 100% to turn the LED on.
Usage:
bumper.set_color(color)
Parameters |
Description |
---|---|
|
The color to set the LED Bumper to:
|
# Build Used: Super Code Base 2.0
def main():
# Blink the LED off and on
while True:
bumper.set_color(GREEN)
wait(0.5, SECONDS)
bumper.set_color(OFF)
wait(0.5, SECONDS)
# Start threads — Do not delete
start_thread(main)
set_brightness#
set_brightness
sets the brightness of the LED Bumper.
Usage:
bumper.set_brightness(color)
Parameters |
Description |
---|---|
|
The brightness of the LED as a percent from 0% to 100%. |
# Build Used: Super Code Base 2.0
def main():
# Light up the LED at different brightnesses
bumper.set_brightness(25)
bumper.set_color(GREEN)
wait(2, SECONDS)
bumper.set_brightness(100)
# Start threads — Do not delete
start_thread(main)
Getter#
is_pressed#
is_pressed
returns a Boolean indicating whether or not the LED Bumper is pressed.
True
– The bumper was pressed.False
– The bumper was not pressed.
Usage:
bumper.is_pressed()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Super Code Base 2.0
def main():
# Turn right when the bumper is pressed
drivetrain.turn(LEFT)
while not bumper.is_pressed():
wait(0.2, SECONDS)
drivetrain.turn(RIGHT)
# Start threads — Do not delete
start_thread(main)