Skip to content
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
6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added lib/pi4j-core-1.3.jar
Binary file not shown.
Binary file added lib/pi4j-core-2.0.jar
Binary file not shown.
Binary file added lib/pi4j-gpio-extension-1.3.jar
Binary file not shown.
Binary file added lib/slf4j-api-1.7.30.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions src/LEDColorController.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import com.pi4j.io.gpio.*; // imports the Pi4j that needs to be installed on the raspberry pi
import java.util.concurrent.TimeUnit; // this is a time related operation for sleeping threads

Expand All @@ -23,3 +24,4 @@ public static void main(String[] args) throws InterruptedException { // throws I
}
}
}

46 changes: 25 additions & 21 deletions src/NumberSequenceUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import javafx.stage.Stage;

public class NumberSequenceUI extends Application { // NumberSequenceUI uses Application abstract class
// !!!This class houses the JavaFX UI!!!

private int[] sequences = {1, 2, 3}; // Array that stores each light sequence.
// Numbers are placeholder for the sequence objects.
private Label output = new Label(); // Creates label object that is used to output the array index as text
// Not set since the output text is variable

SequenceArray sA = new SequenceArray(); // Creates object out of class SequenceArray where the Light Sequences
// are stored in an array

@Override
public void start(Stage primaryStage) { // Method and sets up the JavaFX window
Expand All @@ -21,42 +21,46 @@ public void start(Stage primaryStage) { // Method and sets up the JavaFX window
Button sequence1Button = new Button("Sequence 1");
Button sequence2Button = new Button("Sequence 2");
Button sequence3Button = new Button("Sequence 3");
Button exitAppButton = new Button("Exit");

// Objects that use method setOnAction that makes the button display the correct index from array "sequences"
/* Objects that use method setOnAction that makes the button display the correct index from array "sequences"
using the getIndex method from instantiated object sA ("SequenceArray")
*/
// !!! Need some way to abort the sequence once executed !!!
// !!! Create number generator object to test cancel button !!!
sequence1Button.setOnAction(e -> displaySequence(0));
sequence2Button.setOnAction(e -> displaySequence(1));
sequence3Button.setOnAction(e -> displaySequence(2));
sequence1Button.setOnAction(e -> displaySequence(sA.getIndex(0)));
sequence2Button.setOnAction(e -> displaySequence(sA.getIndex(1)));
sequence3Button.setOnAction(e -> displaySequence(sA.getIndex(2)));
exitAppButton.setOnAction(e -> System.exit(0));

/* Vbox object. As I understand, Vbox is a container that will arrange the child (addAll) button vertically */
VBox vbox = new VBox(10); // 10 pixels specified between each button
vbox.getChildren().addAll(sequence1Button, sequence2Button, sequence3Button, output);
vbox.getChildren().addAll(sequence1Button, sequence2Button, sequence3Button, exitAppButton, output);
// adds the display label below the button for output to screen (they are in order descending)

// Creates scene object that takes the vbox object and formats it to a size. Scene = the layout
// within the window
Scene scene = new Scene(vbox, 60, 150); // (40p W X 100p H)
Scene scene = new Scene(vbox, 60, 200); // (40p W X 100p H)
primaryStage.setScene(scene); // Not super clear on this, but it seems to tie everything together in
// the code examples I studied

primaryStage.show(); // Shows everything
}

// Method used to display the correct sequence number. Calls the index directly from the button.
//The button uses the getIndex method to set and call the correct value
//Included a catch in case I modify this in the future and the index is out of bounds
private void displaySequence(int index) {
// First line makes sure output is valid. Kinda like a catch exception except it heads off the issue.
// "If the index is greater than or = to 0 and is an index and less than the array (sequences) length"
//
if (index >= 0 && index < sequences.length) {
output.setText("Sequence " + sequences[index]);
// Outputs the array index to screen in the displayLabel object - this can be used in the
// future for other output
} else {
output.setText("Invalid Selection."); // JIC we add something that is not an index - for testing
try {
int sequenceValue = index;
output.setText("Sequence " + sequenceValue);
} catch (IndexOutOfBoundsException e) {
output.setText("Invalid Selection."); // Handle invalid index
}



}

}

// Not super sure how start and displaySequence get executed from main since
// I needed ChatGPT to figure out how to tie everything together - N.T.S. Ask Trevor
}
26 changes: 26 additions & 0 deletions src/SequenceArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class SequenceArray {
// !!!Class used for storing the array of sequences!!!

private int[] sequences; // Array that stores each light sequence.


public SequenceArray() {
sequences = new int[]{1, 2, 3}; // Initializes the array with placeholders.
// I'm not sure how to implement the actual sequences yet though.
}

// Loop that iterates over the array to find an index value.
// "Index must be greater than or equal to 0 and no higher then the array length
public int getIndex (int index) {
if (index >= 0 && index < sequences.length) {
return sequences[index];
} else {
throw new IndexOutOfBoundsException("Index out of bounds");
}
}

public int getArrayLength() {
return sequences.length;
}

}