Updated StepperMotorControl Window Shade Example to use setPosition()
Example now saves window shade position in NVS and uses setPosition() accordingly upon initialization.
This commit is contained in:
parent
fe4d83140f
commit
e422d3c9de
|
|
@ -51,23 +51,27 @@ struct DEV_WindowShade : Service::WindowCovering {
|
||||||
|
|
||||||
DEV_WindowShade(int a1, int a2, int b1, int b2) : Service::WindowCovering(){
|
DEV_WindowShade(int a1, int a2, int b1, int b2) : Service::WindowCovering(){
|
||||||
|
|
||||||
current=new Characteristic::CurrentPosition(0);
|
current=new Characteristic::CurrentPosition(0,true);
|
||||||
target=new Characteristic::TargetPosition(0);
|
target=new Characteristic::TargetPosition(0,true);
|
||||||
|
|
||||||
motor=new Stepper_TB6612(a1, a2, b1, b2); // instantiate motor using pins specified in set-up below
|
motor=new Stepper_TB6612(a1, a2, b1, b2); // instantiate motor using pins specified in set-up below
|
||||||
motor->setAccel(10,20); // set acceleration parameters
|
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("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(){
|
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.
|
// 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());
|
LOG1("Setting Shade Position=%d\n",target->getNewVal());
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,11 @@ void setup() {
|
||||||
motor=new Stepper_TB6612(23,32,22,14);
|
motor=new Stepper_TB6612(23,32,22,14);
|
||||||
|
|
||||||
motor->setStepType(StepperControl::HALF_STEP);
|
motor->setStepType(StepperControl::HALF_STEP);
|
||||||
motor->setAccel(10,10);
|
motor->setAccel(10,30);
|
||||||
motor->setPosition(200);
|
motor->move(400,2);
|
||||||
motor->move(100,2);
|
|
||||||
while(motor->stepsRemaining());
|
while(motor->stepsRemaining());
|
||||||
motor->setPosition(-200);
|
motor->setPosition(800);
|
||||||
motor->moveTo(0,2,StepperControl::BRAKE);
|
motor->moveTo(0,2,StepperControl::BRAKE);
|
||||||
while(motor->position()<-11);
|
|
||||||
motor->disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue