Hi, I have a stepper motor Nema 17 with A4988 and Garmin Lidar lite v3
I want to operate both Stepper motor and lidar simultaneously.
According to change lidar sensor length, i want to make stepper motor 'clockwise run, stop, counterclockwise run'
But, It didn't work.. would you mind to tell me any problem with my code?
Garmin LIDAR lite v3
[https://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf]
NEMA17
[https://www.handsontec.com/dataspecs/17HS4401S.pdf]
#include <Wire.h> //
#include <LIDARLite.h>
#include <AccelStepper.h>
LIDARLite lidarlite;
int cnt = 0;
int dist = lidarlite.distance();
const int dirp = 2;
const int stepp = 3;
//State definitions
/*#define RSPD 01
#define RJSTR 02
#define STOPPED 03
//State variable
int state;*/
AccelStepper mystepper(AccelStepper::DRIVER, stepp, dirp);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lidarlite.begin(0,true); //
lidarlite.configure(0); //
mystepper.setMaxSpeed(200);
mystepper.setSpeed(50); //
mystepper.moveTo(-800);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(dist);
/* switch(state){
case RSPD :
mystepper.runSpeed();
break;
case RJSTR:
mystepper.run();
break;
case STOPPED:
break;
}*/
if(dist<30){
mystepper.runSpeed();
}
else if(dist >= 30 && dist <= 150){
mystepper.stop();
mystepper.runToPosition();
mystepper.moveTo(0);
mystepper.setAcceleration(20);
}
else if(dist>150){
mystepper.run();
}
}