Skip to content
Snippets Groups Projects
Final_Coil_Insertion_Code.ino 1.35 KiB
Newer Older
patelpb's avatar
patelpb committed
#include <Stepper.h>
#include <ESP.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
const int rpm = 200;
const int MAXSTEPS = 10;
// for your motor
//asdfasdfasdf

const int PIN1 = D1;
const int PIN2 = D2;
const int PIN3 = D3;
const int PIN4 = D4;


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, PIN1, PIN2, PIN3, PIN4);

int stepCount = 0;  // number of steps the motor has taken

int doSteps(int num_steps){
  int numRevs = 0;
  int do_count = num_steps / MAXSTEPS; 
  int count_remainder = num_steps % MAXSTEPS;

  for(int i = 0; i < do_count; ++i){
      myStepper.step(-MAXSTEPS);
      //Serial.print("Increment: ");

      if (i % 20 == 0){
        Serial.printf("Number of Revolutions: %d\n", numRevs++);        
      }
      ESP.wdtFeed(); //yield; feeds the watchdog (resets the software timer)
  }

  myStepper.step(count_remainder);
  ESP.wdtFeed();
  return numRevs;
  
}



void setup() {
  ESP.wdtDisable();
  pinMode(PIN1, OUTPUT);
  pinMode(PIN2, OUTPUT);
  pinMode(PIN3, OUTPUT);
  pinMode(PIN4, OUTPUT);

  Serial.begin(115200);

  myStepper.setSpeed(rpm);
  
  // step 1/100 of a revolution:
  int numRevolutions = (int) 1e5;
  
  doSteps(numRevolutions * stepsPerRevolution);
  Serial.println(stepCount);
}

void loop() {
  
  
  ESP.wdtFeed();
  
  //delay(500);
}