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
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ lib_deps =
paulstoffregen/Encoder@^1.4.2
andrealombardo/L298N@^2.0.3
waspinator/AccelStepper@^1.64
stepper
upload_port = COM4
monitor_speed = 115200
20 changes: 17 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#include <Arduino.h>
#include "motorControl.h"
#include "shooting.h"

motorControl controller;
shooting shooter;
stepStruct reading;

//previous count for shooting to ensure fire one puck at a time
int prevCount = 0;

//function prototype:
void serialCommunicate();

void setup() {
Serial.begin(115200);
controller.setup();
shooter.setup();
while (!Serial) {
; // Wait for the serial port to be ready
}
Expand Down Expand Up @@ -46,9 +52,9 @@ void loop() {
void serialCommunicate(){
if (Serial.available() > 0) {
String inputString = Serial.readStringUntil('\n'); // Read until newline

// Separate the comma-separated values
int values[4];
int values[5];
int currentIndex = 0;
int commaIndex = inputString.indexOf(',');
while (commaIndex != -1) {
Expand All @@ -59,12 +65,18 @@ void serialCommunicate(){
}

// Handle the last value
if (currentIndex < 4) {
if (currentIndex < 5) {
values[currentIndex] = inputString.toInt();
}

//write the values to the arduino
controller.updateMotors(values[0], values[1], values[2], values[3]);

//loading and shooting values write to arduino
if(values[4] > prevCount){
shooter.shoot();
prevCount = values[4];
}
}
//read from the motor
reading = controller.readSteppers();
Expand All @@ -75,6 +87,8 @@ void serialCommunicate(){
Serial.print(reading.step3);
Serial.print(',');
Serial.print(reading.step4);
Serial.print(',');
Serial.print(prevCount);
Serial.println();

//move steps
Expand Down
29 changes: 29 additions & 0 deletions src/shooting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "shooting.h"

shooting::shooting() :myStepper(200, IN1, IN2, IN3, IN4){
// Constructor initializer list to initialize myStepper
}

shooting::~shooting() {

}

void shooting::setup() {
myStepper.setSpeed(25);
pinMode(Solenoid, OUTPUT);
}


void shooting::shoot(){
//Shooting Code, may need to adjust delays
digitalWrite(Solenoid, HIGH);
delay(100);
digitalWrite(Solenoid, LOW);
myStepper.step(-130); //Switch Solenoid ON
//delay(100);
//Switch Solenoid OFF
//Reload code
//need to verify rotation duration/trial&error?
//delay(300);
myStepper.step(130);
}
28 changes: 28 additions & 0 deletions src/shooting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef shooting_h
#define shooting_h

#include <Arduino.h>
#include <Stepper.h>


class shooting {
public:
shooting(); //constructor
virtual ~shooting(); //virtual destructor
void setup();
void shoot();

protected:
//solenoid pin
int Solenoid = 50;//pin value

//motors
int IN1 = 42;//1
int IN2 = 44;//2
int IN3 = 46;//3
int IN4 = 48;//4

Stepper myStepper;// Declare Stepper instance as a member variable
};

#endif