Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Send bytes every other loop to stress arduino less
Browse files Browse the repository at this point in the history
  • Loading branch information
PatribotsProgramming committed Oct 9, 2023
1 parent 1a441d6 commit 8cf9bb5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/hardware/ArduinoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class ArduinoController {
private Queue<Integer> queue = new LinkedList<Integer>();
private int currentBellyPanState = -1;
private int currentArmState = -1;
private boolean everyOtherLoop = false;

public void periodic() {
// Toggle our boolean to not overload the arduino with requests
everyOtherLoop = !everyOtherLoop;
// Write the latest byte in the queue to the arduino
// If it exists
if (queue.peek() != null) {
Expand Down Expand Up @@ -68,12 +71,15 @@ public void setLEDState(int state, boolean override) {
}

public void sendByte() {
// Send the latest queue value to the arduino,
// Then, remove the latest value from the queue
if (queue.peek() != null) {
// System.out.println("Sending byte: " + queue.peek());
arduino.write(LEDConstants.ARDUINO_ADDRESS, queue.poll());
}
// Only send bytes every other loop to not overload arduino
if (everyOtherLoop) {
// Send the latest queue value to the arduino,
// Then, remove the latest value from the queue
if (queue.peek() != null) {
System.out.println("Sending byte: " + queue.peek());
arduino.write(LEDConstants.ARDUINO_ADDRESS, queue.poll());
}
}
}

public void setBellyPanState(int state) {
Expand Down

0 comments on commit 8cf9bb5

Please sign in to comment.