Hello together,
I want to build a camera slide with a belt, which is powered with a stepper motor. I am using the L293D as a driver. I want to keep the program as simple as possible.
On each side of the slide there should be button which should change the direction of the stepper when the button is touched by the sled. I tried a lot of different ways but I don’t know how to continue. Maybe some of you could help me and I would appreciate that very much.
I will copy my current code in here that u can see what I tried. I know that it is a little bit unclean.
Thanks in Advance
Lukas
#include <Stepper.h>
//int inlPin = 13;
const int stepsU = 200;
//Taster Start-Stop
const int pin_start = 2;
const int interrupt_stop = 3;
//Variablen
volatile bool taster_start = LOW;
volatile bool taster_stop = LOW;
int i, k = 0;
Stepper myStepper(stepsU,9,10,11,12);
void setup()
{
//pinMode(inlPin, OUTPUT);
myStepper.setSpeed(100);
pinMode(pin_start, INPUT_PULLUP);
pinMode(interrupt_stop, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interrupt_stop), STOP, CHANGE);
}
void loop()
{
taster_start = !digitalRead(pin_start);
taster_stop = !digitalRead(interrupt_stop);
i = 0;
if (taster_start){
do{
myStepper.step(HIGH);
//if (taster_stop){
// return 0;
// }
i++;
} while (i < 1000);
i = 0;
}
/*if (interrupt_stop){
myStepper.step(-HIGH);
}*/
}
void STOP(){
myStepper.step(HIGH);
}