Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lleds #2

Open
wants to merge 4 commits into
base: leds
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2023.2.1"
id "edu.wpi.first.GradleRIO" version "2023.4.3"
}

sourceCompatibility = JavaVersion.VERSION_11
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
11 changes: 6 additions & 5 deletions src/main/java/frc/team3128/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

Expand All @@ -25,15 +26,15 @@ public void robotInit(){

@Override
public void robotPeriodic(){
// m_robotContainer.updateDashboard();
//m_robotContainer.updateDashboard();
}

@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
}
//m_autonomousCommand = m_robotContainer.getAutonomousCommand();
//if (m_autonomousCommand != null) {
//m_autonomousCommand.schedule();
//}
}

@Override
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/frc/team3128/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
//import frc.team3128.commands.TestDrive;
import frc.team3128.common.hardware.input.NAR_Joystick;
import frc.team3128.common.narwhaldashboard.NarwhalDashboard;
import frc.team3128.subsystems.TestBenchPiston;
import frc.team3128.subsystems.Led;
import frc.team3128.subsystems.TestBenchMotor;

/**
Expand All @@ -21,13 +23,14 @@
public class RobotContainer {

//private NAR_Drivetrain m_drive;
private TestBenchMotor testBenchMotor;
private TestBenchPiston testBenchPiston;
//private TestBenchMotor testBenchMotor;
//private TestBenchPiston testBenchPiston;
private NAR_Joystick m_leftStick;
private NAR_Joystick m_rightStick;
private Led m_LedStrip;

private CommandScheduler m_commandScheduler = CommandScheduler.getInstance();
private Command auto;
//private Command auto;

private boolean DEBUG = false;

Expand All @@ -39,12 +42,15 @@ public RobotContainer() {

m_leftStick = new NAR_Joystick(0);
m_rightStick = new NAR_Joystick(1);
testBenchPiston = new TestBenchPiston();
//testBenchPiston = new TestBenchPiston();

m_LedStrip = new Led();
// testBenchMotor = new TestBenchMotor();
//m_commandScheduler.setDefaultCommand(testBenchSubsystem, new TestDrive(testBenchSubsystem));

configureButtonBindings();
dashboardInit();
new InstantCommand(m_LedStrip::setYellow,m_LedStrip);
}

private void configureButtonBindings() {
Expand All @@ -57,9 +63,19 @@ private void configureButtonBindings() {
// m_rightStick.getButton(2).onTrue(new RunCommand(testBenchMotor::runReverse,testBenchMotor));
// m_rightStick.getButton(2).onFalse(new RunCommand(testBenchMotor::stop2,testBenchMotor));

m_rightStick.getButton(1).onTrue(new RunCommand(testBenchPiston::eject,testBenchPiston));
//m_rightStick.getButton(1).onTrue(new RunCommand(testBenchPiston::eject,testBenchPiston));

//m_rightStick.getButton(2).onTrue(new RunCommand(testBenchPiston::retract,testBenchPiston));
m_rightStick.getButton(3).onTrue(new InstantCommand(m_LedStrip::setYellow,m_LedStrip));

m_rightStick.getButton(4).onTrue(new InstantCommand(()-> m_LedStrip.ChangeValue(-1)));
m_rightStick.getButton(5).onTrue(new InstantCommand(()-> m_LedStrip.ChangeValue(1)));

m_rightStick.getButton(2).onTrue(new RunCommand(testBenchPiston::retract,testBenchPiston));
m_rightStick.getButton(6).onTrue(new InstantCommand(()-> m_LedStrip.ChangeSaturation(-1)));
m_rightStick.getButton(7).onTrue(new InstantCommand(()-> m_LedStrip.ChangeSaturation(1)));

m_rightStick.getButton(8).onTrue(new InstantCommand(()-> m_LedStrip.ChangeValue(-1)));
m_rightStick.getButton(9).onTrue(new InstantCommand(()-> m_LedStrip.ChangeValue(1)));
}

private void dashboardInit() {
Expand All @@ -74,9 +90,9 @@ public void stopDrivetrain() {
//m_drive.stop();
}

public Command getAutonomousCommand() {
return auto;
}
//public Command getAutonomousCommand() {
//return auto;
//}

// public void updateDashboard() {
// SmartDashboard.putNumber("xxxxxxMotorRPMxxxxxxx", testBenchMotor.logRPM());
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/frc/team3128/subsystems/Led.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package frc.team3128.subsystems;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Led extends SubsystemBase{
private static Led instance;
private AddressableLED m_led;
private AddressableLEDBuffer m_ledBuffer;
private int Hue;
private int Saturation;
private int Value;

public Led(){
InitLeds();
}
public static synchronized Led getInstance() {
if (instance == null) {
instance = new Led();
}
return instance;
}

public void InitLeds() {
m_led = new AddressableLED(9);

m_ledBuffer = new AddressableLEDBuffer(288);
m_led.setLength(m_ledBuffer.getLength());

m_led.setData(m_ledBuffer);
m_led.start();
}

public void setYellow() {
for (var i = 0; i < m_ledBuffer.getLength(); i++) {
// Sets the specified LED to the RGB values for red
m_ledBuffer.setHSV(i, 130, 255, 50);
Hue = 140;
Saturation = 252;
Value = 252;
}

m_led.setData(m_ledBuffer);
}

public void setRGB(int r, int g, int b) {
for (var i = 0; i < m_ledBuffer.getLength(); i++) {
// Sets the specified LED to the RGB values for red
m_ledBuffer.setRGB(i, r, g, b);
}

m_led.setData(m_ledBuffer);
}
public void setHSV(int h, int s, int v) {
for (var i = 0; i < m_ledBuffer.getLength(); i++) {
// Sets the specified LED to the HSV values for red
m_ledBuffer.setHSV(i, h, s, v);
}

m_led.setData(m_ledBuffer);
}

public void ChangeHue(int change) {
Hue = Hue + change;
setHSV(Hue, Saturation, Value);
}
public void ChangeSaturation(int change) {
Saturation = Saturation + change;
setHSV(Hue, Saturation, Value);
}
public void ChangeValue(int change) {
Value = Value + change;
setHSV(Hue, Saturation, Value);
}



}