I am totally new to programming and I am trying to use a stepper motor to build a controller for opening and closing a latch. I am doing this through a the motor turning a screw which pushes a nut that is attached to the latch. my idea is that I can calculate exactly how many rotations that is needed to fully close/open the latch and therefor know how many percent open the latch is by knowing how many rotations in the two directions the motor has taken.
My problem is I am having a hard time storing the number of rotation the motor has done. I have tried to Google but not been able to make it work. I have been unsuccessful creating a variable (in my case the "oldpo" variable) that updates is self with a new value.
The result of my code below is that the motor turns the inputted amount of steps in one direction, and does the same procedure the other direction. It does not save the value in "oldpo".
Thanks in advance!
#include <Stepper.h>
int in1Pin = 11;
int in2Pin = 10;
int in3Pin = 9;
int in4Pin = 8;
currentpo = Serial.parseInt(); //currentpo is never used after reading
steps = newpo - oldpo; //oldpo and newpo are both zero so steps will now be zero
oldpo = newpo; //both still zero
Nope I was just checking if they had the same value or not.
I want to transfer the new position (which is entered manually in serial) to the oldpo variable so that the information can be used the next time I want to enter a new position and calculate how many steps the motor has to take to get to the new position