From e422d3c9de937609cedc15c36064ea9545f70778 Mon Sep 17 00:00:00 2001 From: Gregg Date: Tue, 20 Jun 2023 21:23:03 -0500 Subject: [PATCH] Updated StepperMotorControl Window Shade Example to use setPosition() Example now saves window shade position in NVS and uses setPosition() accordingly upon initialization. --- .../StepperMotorControl/StepperMotorControl.ino | 12 ++++++++---- src/src/extras/extras.ino | 9 +++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/Other Examples/StepperMotorControl/StepperMotorControl.ino b/examples/Other Examples/StepperMotorControl/StepperMotorControl.ino index e66ea5f..80a4fef 100644 --- a/examples/Other Examples/StepperMotorControl/StepperMotorControl.ino +++ b/examples/Other Examples/StepperMotorControl/StepperMotorControl.ino @@ -51,23 +51,27 @@ struct DEV_WindowShade : Service::WindowCovering { DEV_WindowShade(int a1, int a2, int b1, int b2) : Service::WindowCovering(){ - current=new Characteristic::CurrentPosition(0); - target=new Characteristic::TargetPosition(0); + current=new Characteristic::CurrentPosition(0,true); + target=new Characteristic::TargetPosition(0,true); motor=new Stepper_TB6612(a1, a2, b1, b2); // instantiate motor using pins specified in set-up below motor->setAccel(10,20); // set acceleration parameters LOG0("Configuring Motorized Window Shade with input pins: A1=%d, A2=%d, B1=%d, B2=%d\n",a1,a2,b1,b2); + LOG0("Initial Position: %d\n",current->getVal()); + motor->setPosition(current->getVal()*10); } /////////// boolean update(){ - // Move motor to absolute position, assuming 200 steps per revolution and 20 revolutions for full up/travel travel. + // Move motor to absolute position, assuming 200 steps per revolution and 5 revolutions for full up/travel travel, + // for a total of 1000 steps of full travel. + // Specify that motor should enter the BRAKE state upon reaching to desired position. - motor->moveTo(target->getNewVal()*20,5,Stepper_TB6612::BRAKE); + motor->moveTo(target->getNewVal()*10,5,Stepper_TB6612::BRAKE); LOG1("Setting Shade Position=%d\n",target->getNewVal()); return(true); } diff --git a/src/src/extras/extras.ino b/src/src/extras/extras.ino index d371102..7dba94b 100644 --- a/src/src/extras/extras.ino +++ b/src/src/extras/extras.ino @@ -45,14 +45,11 @@ void setup() { motor=new Stepper_TB6612(23,32,22,14); motor->setStepType(StepperControl::HALF_STEP); - motor->setAccel(10,10); - motor->setPosition(200); - motor->move(100,2); + motor->setAccel(10,30); + motor->move(400,2); while(motor->stepsRemaining()); - motor->setPosition(-200); + motor->setPosition(800); motor->moveTo(0,2,StepperControl::BRAKE); - while(motor->position()<-11); - motor->disable(); } //////////////////////////////////////