Hello there!
Quickly about my project,
I'm trying to do an automated wire cutter as school project, the idea is that one motor will feed the wire through encoder which is going to measure length (which is supposed to be shown on LCD), when desired length is going to be hit (in this scenario 23mm) the first motor will shut of and second one will do one full cycle as to cut off the desired length.
The issue I'm having at the moment is I cannot sort out how to keep the first motor running until it hits the threshold and then engaging the second one just for that one cycle.
I made it work that one of the motors works all the time but arduino doesn't record the inputs from encoder and displays nothing on LCD
The other scenario is that when the threshold is hit given by encoder the other motor spins all the time, which is supposed to do only one full spin.
#include <MultiStepper.h>
#include <AccelStepper.h>
#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
const int stepPin1 = 3;
const int dirPin1 = 4;
const int stepPin2 = 5;
const int dirPin2 = 6;
#define inputA 9
#define inputB 8
int counter = 0;
int angle = 0;
int aState;
int aLastState;
void setup() {
pinMode (inputA,INPUT);
pinMode (inputB,INPUT);
pinMode(stepPin1,OUTPUT);
pinMode(dirPin1,OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
aLastState = digitalRead(inputA);
lcd.begin(16,2);
}
void loop() {
aState = digitalRead(inputA);
if (aState != aLastState){
if (digitalRead(inputB) != aState) {
counter ++;
angle ++;
}
else {
counter--;
angle --;
}
lcd.clear();
lcd.print("Length: ");
lcd.print(int(counter*(1.15)));
lcd.print("mm");
lcd.setCursor(0,0);
}
aLastState = aState;
if (angle == 20) {
digitalWrite(dirPin1,HIGH);
for(int x = 0; x < 10; x++) {
digitalWrite(stepPin1,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1,LOW);
delayMicroseconds(500);
}
if (angle != 20) {
digitalWrite(dirPin2,HIGH);
for(int x = 0; x < 10; x++) {
digitalWrite(stepPin2,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin2,LOW);
delayMicroseconds(500);
}
}
}
}
Thanks!
PS: I'm fairly new to the arduino scene, sorry if any of this is not up to standard or question seems stupid, I tried to google couple of solutions but couldn't find much.
PPS: Im using Pololua4988 drivers for motors.