I was having similar problems to others in this thread trying to use this library with buttons etc. The issue seems to be that you need to call at least one stepper function before you call run() or else code execution haults. I haven't looked at the library but more than likely there's some initalized value that's no good.
So in your setup() method, just add something small like:
stepper.rotateDegrees(1);
and everything should be fine.
ChristopheDV:
I did some tests with the Custom Stepper Library and it worked.
At startup my motor turns 90 degrees to left and then 90 degrees to the right, which is correct according to the code.
What I want, is when I push button1 the motor turns 90 degrees to the left and when I press button2 , 90 degrees to the right.
This is the working code (example)
#include <CustomStepper.h>
CustomStepper stepper(8, 9, 10, 11);
boolean rotatedeg = false;
void setup()
{
stepper.setRPM(12);
stepper.setSPR(4075.7728395);
}
void loop()
{
if (stepper.isDone() && rotatedeg == false)
{
stepper.setDirection(CW);
stepper.rotateDegrees(360);
rotatedeg = true;
}
stepper.run();
}
Here's my changed code which is not working (with the implementation of the 1 button)
#include <CustomStepper.h>
CustomStepper stepper(8, 9, 10, 11);
boolean rotate1 = false;
boolean rotatedeg = false;
boolean crotate = false;
const int buttonPin = 4;
int buttonState = 0;
void setup()
{
pinMode(buttonPin, INPUT);
stepper.setRPM(12);
stepper.setSPR(4075.7728395);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
stepper.setDirection(CW);
stepper.rotateDegrees(360);
rotatedeg = true;
stepper.run();
}
}
Is there somebody facing the same problem, or can somebody help me with this?
Thank you