aboutsummaryrefslogtreecommitdiff
path: root/Arduino2024
diff options
context:
space:
mode:
Diffstat (limited to 'Arduino2024')
-rw-r--r--Arduino2024/NewMotor/NewMotor.ino54
1 files changed, 49 insertions, 5 deletions
diff --git a/Arduino2024/NewMotor/NewMotor.ino b/Arduino2024/NewMotor/NewMotor.ino
index 794dd00..48745fa 100644
--- a/Arduino2024/NewMotor/NewMotor.ino
+++ b/Arduino2024/NewMotor/NewMotor.ino
@@ -14,7 +14,7 @@ long pos5 = 3312;
long pos6 = 4140;
long pos7 = 4968;
long pos8 = 5796;
-long pos9 = 6624;
+long pos9 = 6624;
long pos10 = 7452;
int stepsToMove = 828;
@@ -24,7 +24,8 @@ MoToStepper stepper( 400, STEPDIR );
void setup()
{
- Serial.begin(9600);
+ Serial.begin(115200);
+ Serial.println("ESP32 is ready");
stepper.attach( stepPin, dirPin );
stepper.setSpeedSteps(20000); // = 75 steps/second (steps in 10 seconds)
@@ -34,7 +35,51 @@ void setup()
void loop()
{
- stepper.moveTo(pos9);
+ if (Serial.available()>0){
+ String command = Serial.readStringUntil('/n'); //read communication until next line
+ command.trim();//removes any spaces before and after
+
+ int firstSpaceIndex = command.indexOf(' ');//find the first space
+ if(firstSpaceIndex != -1)
+ {
+ String commandName = command.substring(0, firstSpaceIndex);
+
+ int secondSpaceIndex = command.indexOf(' ', firstSpaceIndex + 1);
+ if(secondSpaceIndex != -1){
+ int pumpNumber = command.substring(firstSpaceIndex + 1, secondSpaceIndex).toInt();
+ int pumpValue = command.substring(secondSpaceIndex + 1).toInt();
+
+ if(commandName == "Pump")
+ {
+ Pump(pumpNumber, pumpValue);
+ }
+ } else{
+ int positionValue = command.substring(firstSpaceIndex + 1).toInt();
+
+ if(commandName == "Position"){
+ GoToPosition(positionValue);
+ }
+ }
+ }
+ }
+
+}
+
+void GoToPosition(int value){
+ //execute code
+ Serial.print("Position command executed with value: ");
+ Serial.println(value);
+}
+void Pump(int number,int value){
+ //Execute code
+ Serial.print("Pump: ");
+ Serial.println(number);
+ Serial.println(" value: ");
+ Serial.println(value);
+
+}
+/*
+stepper.moveTo(pos9);
while(stepper.distanceToGo() > 0);
Serial.write("current position :");
delay(stepDelay);
@@ -48,5 +93,4 @@ void loop()
while(stepper.distanceToGo() > 0);
delay(stepDelay);
-
-} \ No newline at end of file
+*/ \ No newline at end of file