diff --git a/components/led_screen.py b/components/led_screen.py index 7c1709b3..10d410b0 100644 --- a/components/led_screen.py +++ b/components/led_screen.py @@ -1,33 +1,92 @@ import wpilib +from components.logo import logo, logo_num_rows + class LEDScreen: led: wpilib.AddressableLED def __init__(self): self.led_length = 72 - self.led_bottom = wpilib.AddressableLED.LEDData(255, 0, 0) - self.led_middle = wpilib.AddressableLED.LEDData(0, 255, 0) - self.led_top = wpilib.AddressableLED.LEDData(0, 0, 255) + self.led_row_length = int(self.led_length / 3) + self.led_bottom_row_colour = wpilib.AddressableLED.LEDData(255, 0, 0) + self.led_middle_row_colour = wpilib.AddressableLED.LEDData(0, 255, 0) + self.led_top_row_colour = wpilib.AddressableLED.LEDData(0, 0, 255) + self.led_raster = [ + [wpilib.AddressableLED.LEDData() for _ in range(self.led_row_length)] + for _ in range(3) + ] + self.animating = False + self.IMAGE_ROWS_BETWEEN_LED_ROWS = 5 + self.image = logo + self.image_num_rows = logo_num_rows + self.current_image_row = 0 + # Move the image after this number of ticks + self.animation_period = 20 + self.current_animation_cycle = 0 def setup(self) -> None: self.led.setLength(self.led_length) self.led_rows = ( - [self.led_bottom] * int(self.led_length / 3) - + [self.led_middle] * int(self.led_length / 3) - + [self.led_top] * int(self.led_length / 3) + [self.led_bottom_row_colour] * self.led_row_length + + [self.led_middle_row_colour] * self.led_row_length + + [self.led_top_row_colour] * self.led_row_length ) self.led.setData(self.led_rows) self.led.start() def set_bottom_row(self, r, g, b) -> None: - self.led_bottom.setRGB(r, g, b) + self.led_bottom_row_colour.setRGB(r, g, b) def set_middle_row(self, r, g, b) -> None: - self.led_middle.setRGB(r, g, b) + self.led_middle_row_colour.setRGB(r, g, b) def set_top_row(self, r, g, b) -> None: - self.led_top.setRGB(r, g, b) + self.led_top_row_colour.setRGB(r, g, b) + + def animate(self) -> None: + self.current_image_row = 0 + self.load_row(self.current_image_row) + self.animating = True + self.led.setData(self.led_raster[0] + self.led_raster[1] + self.led_raster[2]) def execute(self) -> None: - self.led.setData(self.led_rows) + if not self.animating: + self.led.setData(self.led_rows) + else: + # step to next set of raster lines, if it's time + self.current_animation_cycle = ( + self.current_animation_cycle + 1 + ) % self.animation_period + if self.current_animation_cycle == 0: + self.current_image_row = ( + self.current_image_row + 1 + ) % self.image_num_rows + self.load_row(self.current_image_row) + self.led.setData( + self.led_raster[0] + self.led_raster[1] + self.led_raster[2] + ) + + def load_row(self, image_row) -> None: + second_image_row = ( + image_row + self.IMAGE_ROWS_BETWEEN_LED_ROWS + ) % self.image_num_rows + third_image_row = ( + second_image_row + self.IMAGE_ROWS_BETWEEN_LED_ROWS + ) % self.image_num_rows + for i in range(0, len(self.image[image_row])): + self.led_raster[0][i].setRGB( + self.image[image_row][i][0], + self.image[image_row][i][1], + self.image[image_row][i][2], + ) + self.led_raster[1][i].setRGB( + self.image[second_image_row][i][0], + self.image[second_image_row][i][1], + self.image[second_image_row][i][2], + ) + self.led_raster[2][i].setRGB( + self.image[third_image_row][i][0], + self.image[third_image_row][i][1], + self.image[third_image_row][i][2], + ) diff --git a/components/logo.py b/components/logo.py new file mode 100644 index 00000000..1635e5c1 --- /dev/null +++ b/components/logo.py @@ -0,0 +1,445 @@ +logo_num_rows = 17 +logo = [ + [ + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [246, 246, 246], + [231, 231, 231], + [69, 69, 69], + [119, 119, 119], + [216, 216, 216], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [216, 216, 216], + [119, 119, 119], + [69, 69, 69], + [231, 231, 231], + [246, 246, 246], + [255, 255, 255], + [255, 255, 255], + ], + [ + [221, 221, 221], + [128, 128, 128], + [116, 116, 116], + [129, 129, 129], + [138, 138, 138], + [103, 103, 103], + [216, 216, 216], + [145, 145, 145], + [115, 115, 115], + [237, 237, 237], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [237, 237, 237], + [114, 114, 114], + [144, 144, 144], + [216, 216, 216], + [103, 103, 103], + [138, 138, 138], + [129, 129, 129], + [116, 116, 116], + [129, 129, 129], + [221, 221, 221], + ], + [ + [221, 221, 221], + [187, 187, 187], + [116, 116, 116], + [108, 108, 108], + [233, 233, 233], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [228, 228, 228], + [107, 107, 107], + [210, 210, 210], + [255, 255, 255], + [255, 255, 255], + [209, 209, 209], + [106, 106, 106], + [228, 228, 228], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [233, 233, 233], + [108, 108, 108], + [116, 116, 116], + ], + [ + [187, 187, 187], + [255, 255, 255], + [239, 239, 239], + [94, 94, 94], + [210, 210, 210], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [253, 253, 253], + [121, 121, 121], + [228, 228, 228], + [228, 228, 228], + [121, 121, 121], + [253, 253, 253], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [210, 210, 210], + [94, 94, 94], + [239, 239, 239], + ], + [ + [255, 255, 255], + [252, 252, 252], + [100, 100, 100], + [234, 234, 234], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [254, 254, 254], + [250, 250, 250], + [255, 255, 255], + [255, 255, 255], + [245, 245, 245], + [170, 170, 170], + [170, 170, 170], + [245, 245, 245], + [255, 255, 255], + [255, 255, 255], + [250, 250, 250], + [254, 254, 254], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [233, 233, 233], + [99, 99, 99], + ], + [ + [252, 252, 252], + [157, 157, 157], + [198, 198, 198], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [187, 187, 187], + [39, 22, 22], + [147, 138, 138], + [248, 248, 248], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [248, 248, 248], + [147, 138, 138], + [39, 22, 22], + [187, 187, 187], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [197, 197, 197], + ], + [ + [158, 158, 158], + [108, 108, 108], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [252, 252, 252], + [188, 0, 0], + [105, 27, 27], + [217, 217, 217], + [234, 234, 234], + [228, 228, 228], + [216, 216, 216], + [105, 27, 27], + [188, 0, 0], + [68, 33, 33], + [252, 252, 252], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + ], + [ + [109, 109, 109], + [110, 110, 110], + [150, 150, 150], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [195, 195, 195], + [88, 2, 2], + [144, 0, 0], + [172, 172, 172], + [80, 80, 80], + [16, 16, 16], + [168, 168, 168], + [144, 0, 0], + [88, 2, 2], + [196, 196, 196], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [150, 150, 150], + ], + [ + [110, 110, 110], + [71, 71, 71], + [92, 92, 92], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [183, 183, 183], + [191, 191, 191], + [255, 255, 255], + [14, 14, 14], + [0, 0, 0], + [204, 204, 204], + [190, 190, 190], + [183, 183, 183], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [92, 92, 92], + ], + [ + [71, 71, 71], + [255, 255, 255], + [127, 127, 127], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [235, 235, 235], + [0, 0, 0], + [0, 0, 0], + [149, 149, 149], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [125, 125, 125], + ], + [ + [255, 255, 255], + [255, 255, 255], + [121, 121, 121], + [251, 251, 251], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [202, 202, 202], + [0, 0, 0], + [0, 0, 0], + [106, 106, 106], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [251, 251, 251], + [121, 121, 121], + ], + [ + [255, 255, 255], + [255, 255, 255], + [176, 176, 176], + [185, 185, 185], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [204, 204, 204], + [0, 0, 0], + [0, 0, 0], + [77, 77, 77], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [183, 183, 183], + [178, 178, 178], + ], + [ + [255, 255, 255], + [255, 255, 255], + [252, 252, 252], + [118, 118, 118], + [224, 224, 224], + [112, 112, 112], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [145, 145, 145], + [108, 108, 108], + [212, 212, 212], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [112, 112, 112], + [224, 224, 224], + [117, 117, 117], + [252, 252, 252], + ], + [ + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [199, 199, 199], + [60, 60, 60], + [171, 171, 171], + [167, 167, 167], + [255, 255, 255], + [235, 235, 235], + [204, 204, 204], + [239, 239, 239], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [239, 239, 239], + [204, 204, 204], + [235, 235, 235], + [255, 255, 255], + [167, 167, 167], + [172, 172, 172], + [60, 60, 60], + [199, 199, 199], + [255, 255, 255], + ], + [ + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [197, 197, 197], + [255, 255, 255], + [125, 125, 125], + [197, 197, 197], + [91, 91, 91], + [54, 54, 54], + [219, 219, 219], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [218, 218, 218], + [54, 54, 54], + [91, 91, 91], + [196, 196, 196], + [126, 126, 126], + [255, 255, 255], + [197, 197, 197], + [255, 255, 255], + [255, 255, 255], + ], + [ + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [254, 254, 254], + [119, 119, 119], + [71, 71, 71], + [194, 194, 194], + [245, 245, 245], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [245, 245, 245], + [194, 194, 194], + [71, 71, 71], + [119, 119, 119], + [254, 254, 254], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + ], + [ + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [153, 153, 153], + [117, 117, 117], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [116, 116, 116], + [153, 153, 153], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + [255, 255, 255], + ], +] diff --git a/robot.py b/robot.py index 21fa2333..fc725aed 100755 --- a/robot.py +++ b/robot.py @@ -238,6 +238,14 @@ def testPeriodic(self): if self.driver_joystick.getTriggerPressed(): self.shooter.fire() + if self.driver_joystick.getRawButtonPressed(10): + if not self.led_screen.animating: + self.led_screen.animate() + else: + self.led_screen.setup() + self.led_screen.animating = False + self.led_screen.execute() + if __name__ == "__main__": wpilib.run(MyRobot)