-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from AlphaKnights/LEDs
Implement LED support
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import commands2 | ||
import typing | ||
from subsystems.ledsubsystem import LEDSubsystem | ||
class TeamColorsCommand(commands2.Command): | ||
def __init__(self, led_sub: LEDSubsystem) -> None: | ||
super().__init__() | ||
self.led = led_sub | ||
self.addRequirements(led_sub) | ||
|
||
def execute(self) -> None: | ||
self.led.teamLights() | ||
|
||
def isFinished(self) -> bool: | ||
return False | ||
|
||
def end(self, interrupted: bool) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import math | ||
import typing | ||
|
||
import wpilib | ||
|
||
from commands2 import Subsystem | ||
from constants import LEDConstants | ||
|
||
class LEDSubsystem(Subsystem): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self.led = wpilib.AddressableLED(LEDConstants.kLEDPort) | ||
|
||
self.ledData = [wpilib.AddressableLED.LEDData() for _ in range(LEDConstants.kLEDBuffer)] | ||
|
||
self.led.setLength(LEDConstants.kLEDBuffer) | ||
|
||
self.led.setData(self.ledData) | ||
self.led.start() | ||
|
||
|
||
def periodic(self) -> None: | ||
self.led.setData(self.ledData) | ||
|
||
def lightAll(self, hue: int, sat: int, val: int) -> None: | ||
for i in range(LEDConstants.kLEDBuffer): | ||
self.ledData[i].setHSV(hue, sat, val) | ||
|
||
def teamLights(self) -> None: | ||
for i in range(LEDConstants.kLEDBuffer): | ||
if (i % 2 == 0): | ||
self.ledData[i].setHSV(LEDConstants.kSilverHue, LEDConstants.kSilverSat, LEDConstants.kSilverVal) | ||
else: | ||
self.ledData[i].setHSV(LEDConstants.kBlueHue, LEDConstants.kBlueSat, LEDConstants.kBlueVal) |