hi all
i am having trouble understanding how to go about making this work
i have pieced together code from various sources and created a library for stepper movements
and am having trouble figuring out how i can pass direction variables into the function and have it output to proper pin on arduino
the catch is there are several instances of the class with all different direction output pins i guess i would like to know is there a way to pass a 1 into function call and have it digital write to the pin in the calling instance
im not really sure how to return data from functions or if thats what im even looking for
here is a copy of the source file and header file
// Header file
#ifndef accel_h
#define accel_h
#include "Arduino.h"
class step_Accel {
private:
int _steps;
byte _step_Pin;
byte _DIR;
public:
step_Accel(int steps, byte step_Pin, byte Dir);
void Move(int steps, byte step_Pin, byte Dir);
};
#endif
// Source file
#include "arduino.h"
#include "accel.h"
step_Accel::step_Accel(int steps, byte step_Pin, byte Dir) {
_steps = steps;
_step_Pin = step_Pin;
_DIR = Dir;
} **not sure if this is what i need to pass in the (byte Dir)
void step_Accel::Move(int steps, byte step_Pin, byte Dir) {
if (_DIR == 1) ***this is what i have added for picking direction of rotation and it
digitalWrite(Dir, HIGH); works on my test sketch but as a tab of the sketch***
else
digitalWrite(Dir, LOW);
int lowSpeed = 2000; // Adjust for lowest speed
int highSpeed = 300; // Highest speed is 200 with 400 steps per revolution
int change = 2;
int rampUpStop = (lowSpeed - highSpeed) / change;
if ( rampUpStop > _steps / 2 )
rampUpStop = _steps / 2;
int rampDownStart = _steps - rampUpStop;
int d = lowSpeed;
for (int i = 0; i < _steps; i++) {
digitalWrite(step_Pin, HIGH);
digitalWrite(step_Pin, LOW);
delayMicroseconds(d);
if ( i < rampUpStop )
d -= change;
else if ( i > rampDownStart )
d += change;
} // close for loop
} // close function
here is a copy of the instances i created and a function call
step_Accel cell_Pickup_Extend1 = step_Accel(extend1_Steps, 2, pickup_Dir_Pin);
step_Accel cell_Pickup_Extend2 = step_Accel(extend2_Steps, 2, pickup_Dir_Pin);
step_Accel carriage_Extend = step_Accel(10000, 6, carriage_Dir_Pin);
cell_Pickup_Extend1.Move(extend1_Steps, 2, 1);
a few of the different distances to move
int extend1_Steps = 6000;
int extend2_Steps = 1000;