Skip to content

Commit

Permalink
fixed motor direction, added correct pins to StatusLight
Browse files Browse the repository at this point in the history
  • Loading branch information
AR2100 committed May 18, 2024
1 parent a8d689b commit a648bb3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 53 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[platformio]
default_envs = StepperArm
default_envs = StatusLight

[env:main]
platform = teensy
Expand Down
16 changes: 8 additions & 8 deletions scripts/protobuf/JoystickMotorControl/joystick_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,25 @@ def keyboard_thread():
# print("Press 'esc' to exit...")
# print("Currently pressed keys:", ', '.join(current_keys))
if "Key.up" in current_keys and "Key.down" not in current_keys:
with left_speed_lock:
left_speed = 3000
with right_speed_lock:
right_speed = 3000
elif "Key.up" not in current_keys and "Key.down" in current_keys:
with left_speed_lock:
left_speed = -3000
with right_speed_lock:
right_speed = -3000
elif "Key.right" in current_keys and "Key.left" not in current_keys:
elif "Key.up" not in current_keys and "Key.down" in current_keys:
with left_speed_lock:
left_speed = 3000
with right_speed_lock:
right_speed = -3000
elif "Key.right" not in current_keys and "Key.left" in current_keys:
right_speed = 3000
elif "Key.right" in current_keys and "Key.left" not in current_keys:
with left_speed_lock:
left_speed = -3000
with right_speed_lock:
right_speed = 3000
elif "Key.right" not in current_keys and "Key.left" in current_keys:
with left_speed_lock:
left_speed = 3000
with right_speed_lock:
right_speed = -3000
else:
with left_speed_lock:
left_speed = 0
Expand Down
94 changes: 50 additions & 44 deletions src/StatusLight/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <Messages.hpp>
#include "StatusLight.hpp"

// v1.0 PCB pins
// const int GREEN_PIN = 30;
// const int BLUE_PIN = 31;
// const int RED_PIN = 32;

// protoboard pins
const int GREEN_PIN = 35;
const int BLUE_PIN = 34;
const int RED_PIN = 32;
Expand Down Expand Up @@ -36,57 +42,57 @@ int main() {
pinMode(LED_BUILTIN, OUTPUT);
// status_light::StatusLight statusLight({{"GREEN", GREEN_PIN},{"BLUE", BLUE_PIN},{"RED", RED_PIN}});

// // Ethernet setup
// qindesign::network::Ethernet.begin();
// udp.begin(PORT);
// Ethernet setup
qindesign::network::Ethernet.begin();
udp.begin(PORT);

// // initialize data
// size_t requestLength;
// uint8_t requestBuffer[256];
// initialize data
size_t requestLength;
uint8_t requestBuffer[256];

// handleLEDRequest(RED_PROTO, 1);

while (true) {
// OLD
digitalWrite(GREEN_PIN, HIGH);
delay(500);
digitalWrite(BLUE_PIN, HIGH);
delay(500);
digitalWrite(RED_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
digitalWrite(GREEN_PIN, LOW);
delay(500);
digitalWrite(BLUE_PIN, LOW);
delay(500);
digitalWrite(RED_PIN, LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
// // OLD
// digitalWrite(GREEN_PIN, HIGH);
// delay(500);
// digitalWrite(BLUE_PIN, HIGH);
// delay(500);
// digitalWrite(RED_PIN, HIGH);
// digitalWrite(LED_BUILTIN, HIGH);
// delay(2000);
// digitalWrite(GREEN_PIN, LOW);
// delay(500);
// digitalWrite(BLUE_PIN, LOW);
// delay(500);
// digitalWrite(RED_PIN, LOW);
// digitalWrite(LED_BUILTIN, LOW);
// delay(2000);

// // read incoming UDP messages
// requestLength = udp.parsePacket();
// if (udp.available()) {
requestLength = udp.parsePacket();
if (udp.available()) {

// Serial.println("Packet received: ");
Serial.println("Packet received: ");

// memset(requestBuffer, 0, 256);
// udp.readBytes(requestBuffer, requestLength);
// bool success = protobuf::Messages::decodeStatusLightRequest(requestBuffer, requestLength, requestCommand);
memset(requestBuffer, 0, 256);
udp.readBytes(requestBuffer, requestLength);
bool success = protobuf::Messages::decodeStatusLightRequest(requestBuffer, requestLength, requestCommand);

// Serial.print("[color=");
// Serial.print(requestCommand.color);
// Serial.print(", display=");
// Serial.print(requestCommand.display);
// Serial.println("]");

// // // OLD
// // handleLEDRequest(requestCommand.color, requestCommand.display);
Serial.print("[color=");
Serial.print(requestCommand.color);
Serial.print(", display=");
Serial.print(requestCommand.display);
Serial.println("]");

// // OLD
handleLEDRequest(requestCommand.color, requestCommand.display);

// // NEW
// statusLight.resetLeds();
// statusLight.setLedState("GREEN", HIGH);
// statusLight.setLedBlink("GREEN", requestCommand.display);
// }
// NEW
// statusLight.resetLeds();
// statusLight.setLedState("GREEN", HIGH);
// statusLight.setLedBlink("GREEN", requestCommand.display);
}

// // OLD
// if (blinkTimer >= BLINK_RATE_MS) {
Expand All @@ -106,10 +112,10 @@ int main() {
// NEW
// statusLight.update();

// if (blinkTimer >= BLINK_RATE_MS) {
// blinkTimer -= BLINK_RATE_MS;
// digitalToggle(LED_BUILTIN);
// }
if (blinkTimer >= BLINK_RATE_MS) {
blinkTimer -= BLINK_RATE_MS;
digitalToggle(LED_BUILTIN);
}
}
}

Expand Down

0 comments on commit a648bb3

Please sign in to comment.