Led#
rc.led
Copyright MIT GNU General Public License v3.0
BWSI Autonomous RACECAR Course Racecar Neo LTS
File Name: led.py File Description: Defines the interface of the Led module of the racecar_core library
- class led.Led#
Controls the 84-LED addressable RGB strip in the light band around the car.
Each LED is individually controllable. Colors are (red, green, blue) tuples with each channel in the range [0, 255]. LED 0 is at the front-left end of the band; the index runs back along the left side, around the rear, and forward along the right side to LED 83 at the front-right end.
Note
Until a program sets the LEDs (and again after it exits), the strip shows the battery level: red LEDs grow in from both ends of the band. In the simulator, the strip is the light band of the car’s model.
- abstractmethod clear() None#
Turns every LED off (sets the whole strip to black).
Example:
rc.led.clear()
- abstractmethod get_num_pixels() int#
Returns the number of LEDs on the strip.
Example:
n = rc.led.get_num_pixels()
- abstractmethod get_pixels() List[Tuple[int, int, int]]#
Returns the current color of every LED as a list of (r, g, b) tuples.
- Returns:
One (red, green, blue) tuple per LED, from LED 0 to LED 83, as last set by the program.
Example:
# Shift the strip pattern one LED along the band pixels = rc.led.get_pixels() rc.led.set_pixels(pixels[-1:] + pixels[:-1])
- abstractmethod set_color(color: Tuple[int, int, int]) None#
Sets every LED to the same color.
- Parameters:
color – An (red, green, blue) tuple, each channel in [0, 255].
Example:
# Light the whole strip green rc.led.set_color((0, 255, 0))
- abstractmethod set_pixel(index: int, color: Tuple[int, int, int]) None#
Sets a single LED to a color.
- Parameters:
index – The LED to set, from 0 to get_num_pixels() - 1.
color – An (red, green, blue) tuple, each channel in [0, 255].
- Raises:
IndexError – If index is outside [0, get_num_pixels() - 1].
Example:
# Light the first LED red rc.led.set_pixel(0, (255, 0, 0))
- abstractmethod set_pixels(colors: List[Tuple[int, int, int]]) None#
Sets the strip from a list of colors, one (r, g, b) tuple per LED.
- Parameters:
colors – A list of (red, green, blue) tuples. Extra entries are ignored; missing entries are left unchanged.
Example:
# A red-green gradient n = rc.led.get_num_pixels() rc.led.set_pixels([(i * 255 // n, 255 - i * 255 // n, 0) for i in range(n)])