diff --git a/src/src/extras/extras.ino b/src/src/extras/extras.ino index 36f66bc..da92fc2 100644 --- a/src/src/extras/extras.ino +++ b/src/src/extras/extras.ino @@ -28,33 +28,45 @@ // This is a placeholder .ino file that allows you to easily edit the contents of this files using the Arduino IDE, // as well as compile and test from this point. This file is ignored when the library is included in other sketches. -#include "Stepper_TB6612.h" -#include "Stepper_A3967.h" +#include "Stepper_TB6612.h" // include the driver for a TB6612 chip -StepperControl *motor; +StepperControl *motor; // create a global pointer to StepperControl so it can be accessed in both setup() and loop() -//////////////////////////////////// +/////////////////// void setup() { Serial.begin(115200); delay(1000); - Serial.printf("\nHomeSpan Steppers\n\n"); + Serial.printf("\nHomeSpan Stepper Control\n\n"); -// motor=new Stepper_TB6612(23,32,22,14,33,27,{1,1}); - motor=new Stepper_TB6612(23,32,22,14); + motor=new Stepper_TB6612(23,32,22,14,33,27); // instantiate the motor object (with PWM pins 33 and 27 specified) - motor->setStepType(StepperControl::FULL_STEP_ONE_PHASE); - motor->setAccel(10,20); - motor->move(200,5); + motor->setStepType(StepperControl::HALF_STEP); // set the mode to half-step, which means 400 steps are needed for a complete revolution for a 200-step motor + motor->setAccel(10,20); // add acceleration parameters of 10x spread of 20 steps + + Serial.printf("Moving motor 400 steps and waiting until motor stops...\n"); + + motor->move(-400,5); // move the motor -400 steps (1 revolution), with 2ms between steps. + while(motor->stepsRemaining()); // wait until there no remaining steps + + Serial.printf("Moving motor to absolute position of +1200 (reversing a total of 1600 steps, or 4 revolutions) without waiting...\n"); + + motor->moveTo(1200,2,StepperControl::BRAKE); // move the motor to an absolute position of 1200 steps with 3ms between steps; enter brake state when done + + // Motor will continue moving in background even once setup() exits and loop() below starts } -////////////////////////////////////// +/////////////////// void loop(){ + + Serial.printf("Motor has %d remaining steps\n",motor->stepsRemaining()); + + delay(1000); // motor is unaffected by delay() + + if(motor->position()==1200){ + Serial.printf("Motor has reached final position and is now stopped.\n"); + while(1); + } } - -////////////////////////////////////// - - -//////////////////////////