Skip to content

Commit

Permalink
Merge pull request #152 from thedropbears/led-reset
Browse files Browse the repository at this point in the history
Add reset to blank LEDs after a timeout
  • Loading branch information
james-ward authored Feb 3, 2025
2 parents 428cc24 + 3d0e558 commit 7da4d79
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/led_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
FLASH_SPEED = 2
BREATHE_SPEED = 0.5
RAINBOW_SPEED = 1.5
RESET_TIMEOUT = 2.0


class HsvColour(Enum):
Expand Down Expand Up @@ -64,6 +65,8 @@ def __init__(self, strip_length: int = 5) -> None:
self.leds.setData(self.strip_data)
self.leds.start()

self.last_update_time = time.monotonic()

@feedback
def is_red_right(self) -> bool:
return is_red()
Expand All @@ -73,23 +76,36 @@ def team_colour(self) -> None:
self.pattern = Solid(HsvColour.RED)
else:
self.pattern = Solid(HsvColour.BLUE)
self.keep_alive()

def facing_in_range(self) -> None:
self.pattern = Solid(HsvColour.GREEN)
self.keep_alive()

def not_facing_in_range(self) -> None:
self.pattern = Flash(HsvColour.YELLOW)
self.keep_alive()

def not_in_range(self) -> None:
self.pattern = Solid(HsvColour.RED)
self.keep_alive()

def too_close_to_reef(self) -> None:
self.pattern = Flash(HsvColour.ORANGE)
self.keep_alive()

def rave(self) -> None:
self.pattern = Rainbow(HsvColour.MAGENTA)
self.keep_alive()

def keep_alive(self) -> None:
# Refresh the timer to stop the LEDs being turned off
self.last_update_time = time.monotonic()

def execute(self) -> None:
if time.monotonic() - self.last_update_time > RESET_TIMEOUT:
self.pattern = Solid(HsvColour.OFF)

colour = self.pattern.update()
self.led_data.setHSV(*colour)
self.leds.setData(self.strip_data)
Expand Down

0 comments on commit 7da4d79

Please sign in to comment.