AutoFilm-ESP32/AutoFilmESP32/motor.cpp
2024-06-25 21:17:14 +01:00

30 lines
807 B
C++

#include "motor.h"
void runMotorTask(void* parameter) {
MotorTaskParams* params = (MotorTaskParams*)parameter;
// Enable the motor
digitalWrite(EN_PIN, LOW);
while (true) {
// Rotate clockwise
Serial.println("Rotating CW" + (String)params->cwRotations);
stepper.setCurrentPosition(0);
stepper.moveTo(STEPS_PER_REV * params->cwRotations);
while (stepper.distanceToGo() != 0) {
stepper.run();
}
// Rotate counter-clockwise
Serial.println("Rotating CCW" + (String)params->ccwRotations);
stepper.setCurrentPosition(0);
stepper.moveTo(-STEPS_PER_REV * params->ccwRotations);
while (stepper.distanceToGo() != 0) {
stepper.run();
}
}
// Disable the motor
digitalWrite(EN_PIN, HIGH);
vTaskDelete(NULL); // Delete the task when done
}