1
0
Prechádzať zdrojové kódy

'Stepper_Rotation.ino' löschen

mkebab 1 rok pred
rodič
commit
75303d35b7
1 zmenil súbory, kde vykonal 0 pridanie a 60 odobranie
  1. 0 60
      Stepper_Rotation.ino

+ 0 - 60
Stepper_Rotation.ino

@@ -1,60 +0,0 @@
-#include <AccelStepper.h>
-
-// Define the pinss
-#define STEP_PIN1 5
-#define DIR_PIN1 4
-#define ENABLE_PIN1 6
-
-// Define the steps per revolution of your stepper motor
-const float STEPS_PER_REVOLUTION = 200.0;
-float i = 20;  //Gear Transmission
-
-// Create an instance of the AccelStepper class
-AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN1, DIR_PIN1);
-
-void setup() {
-
-  Serial.begin(9600);  // Set the baud rate to the same value used in Python
-
-  // Set the maximum speed and acceleration (you can adjust these values)
-  stepper.setMaxSpeed(400);
-  stepper.setAcceleration(100.0);
-
-  // Set the enable pin as an output and disable the motor by default
-  pinMode(ENABLE_PIN1, OUTPUT);
-  digitalWrite(ENABLE_PIN1, HIGH);
-
-  // Set the motor direction (0 for clockwise, 1 for counter-clockwise)
-  stepper.setPinsInverted(false, false, true);  // Adjust the last parameter if needed
-}
-
-void loop() {
-  if (Serial.available() > 0) {
-    // Read the incoming value from Python
-    int value = Serial.parseInt();
-    if ((value > -125) && (value < 125)) {
-        rotateStepper(value * i);
-        Serial.println(value);
-      }
-  }
-  delay(1000);
-}
-
-void rotateStepper(float degrees) {
-  // Calculate the number of steps based on the desired angle
-  float steps = degrees * (STEPS_PER_REVOLUTION / 360.0);
-
-  // Move the stepper to the specified number of steps
-  stepper.move(steps);
-
-  // Enable the motor
-  digitalWrite(ENABLE_PIN1, LOW);
-
-  // Run the stepper until it reaches the target position
-  while (stepper.distanceToGo() != 0) {
-    stepper.run();
-  }
-
-  // Disable the motor
-  digitalWrite(ENABLE_PIN1, HIGH);
-}