Hi All,
I'm fairly new to the arduino platform and the accelStepper library.
My question is, (for debug reasons and to see if it can be done :-)) can accelStepper.currentPosition be used to output where the stepper thinks it is?
A section of code that has not yet been tested;
#include <Wire.h>
#include <AccelStepper.h>
#define HALFSTEP 8
#define D6T_addr 0x0A
#define D6T_cmd 0x4C
// Motor pin definitions
#define motorPin1 1 // IN1 on the ULN2003 driver 1
#define motorPin2 2 // IN2 on the ULN2003 driver 1
#define motorPin3 3 // IN3 on the ULN2003 driver 1
#define motorPin4 4 // IN4 on the ULN2003 driver 1
byte rbuf[19];
float temp[9]; // amb + 8 temp_readings
float temp2[9]; // amb + 8 temp_readings to compare with the values in temp
boolean bodyPresent = 0;// boolean to indicate if body is sensed by the DT6 sensor. 1 = body present
const int SWITCH = 22; // input pin for home position indicator
int homeFlag = 0;
int ledPins [] = {5,6,7,8,9,10,11,12}; //array of output pins for leds
long Position = 0;
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
void setup()
{
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(800.0);
stepper1.setSpeed(500);
stepper1.moveTo(5000);// need to adjust this empirically
Wire.begin();
Serial.begin(9600); //
pinMode (homeFlag, INPUT);
for(int index = 0; index < 8; index ++)
{
pinMode(ledPins[index], OUTPUT); //declare LED as output
}
// Initialise flag position
//if the flag is not up, drive it until the homeFlag = HIGH
homeFlag = digitalRead (SWITCH);
if (homeFlag == LOW)
{
while (homeFlag == LOW){
stepper1.run();
}
stepper1.stop();
Position = stepper1.currentPosition; // debug this line to print the motor position.
// this line generates the following compiler error " error: cannot convert 'AccelStepper::currentPosition' from type 'long int (AccelStepper::)()' to type 'long int'
Serial.print (Position);
Serial.println ();
stepper1.setSpeed (500);
}
Any help and comments greatly received :-)