Having a strange problem...
I am developing a function that takes in some parameters and uses those to scan a stepper motor over some angle. Attached to the motor is a solar panel, with its output attached to an ADC. Basically it scans a range, picks a point with the highest value, and moves the cell to that orientation. A somewhat crude prototype of sun-tracking.
Anyhow, I'm using the Stepper library included with the IDE, and this code works fine if I input a number like so: myStepper.step(-50). However, if I pass it an integer with that same value, nothing happens. I get no errors during compile, but the motor just doesn't turn. This is the ONLY change I am making as I try each way.
/*This will sweep a stepper motor through the designated angle while reading ADC values.
During the sweep the voltage of the solar cell will be read and stored in an array. At the conclusion of the
sweep, the maximum value will be found and the number of steps needed to return to the corresponding position
will be returned.
Name: Sergey Feingold
Date: 9-16-11
--Inputs--
angle: This is the angle in degrees through which the stepper will move. The starting position is assumed to
bisect the angle, therefore an input of 180 will sweep 90° each direction before returning to center.
stepsPerRev: The is the number of steps per revolution of the stepper motor. This is required to ensure correct
amount of movement.
numAverages: This is the number of times that the ADC value will be averaged at each step. More averages will result in a slower sweep.
pinADC: This is the ADC pin that will be be analyzed
*/
void sweep(int angle, int stepsPerRev, int numAverages, int pinADC)
{
// Stepper Parameters
myStepper.setSpeed(25);
const int stepsPerRevolution = stepsPerRev;
char cellVoltages[200];
int currentStep = 0;
int stepCount = 0;
int totalSteps = (angle/360)*400;
int halfSweep = totalSteps/2;
int CW = 1;
int CCW = -1;
int halfSweepCW = halfSweep * CW;
int halfSweepCCW = halfSweep * CCW;
myStepper.step(halfSweepCW);
}
Any thoughts? I glanced at Stepper.cpp to examine that function but I can't see any obvious reason why an integer shouldn't work.
As a tangential issue, is there a "cheap" way to do quadratic interpolation? I will start by using a simple function to find the maximum value of the ADC, but of course it is likely there will be multiple and equal maximums. How to circumvent this?
Any help is appreciated! These forums are wonderful.