#include <mechButton.h>
#include <idlers.h>
#include <AccelStepper.h>
#define BUTTON_PIN1 4 // Pin we'll hook a button to. The other side hooks to ground.
#define BUTTON_PIN2 5 // Pin we'll hook a button to. The other side hooks to ground.
#define motorInterfaceType 1
const int stepPin = 3; // Set the stepping pin to pin 9
const int dirPin = 2; // Set the direct pin to pin 8
int currentSpeed = 100; // Create a variable for speed
int positionOfReel = 0; // position of needed number
int rotationCount = 10; //count of full rotation of reel; x4 in future
mechButton button1(BUTTON_PIN1); // Set button one to pin 4.
mechButton button2(BUTTON_PIN2); // Set button one to pin 4.
AccelStepper myStepper(motorInterfaceType, stepPin, dirPin);
// Your standard sketch setup()
void setup() {
button1.setCallback(myCallback1); // Set up #1's callback. (Don't use Analog for buttons.)
button2.setCallback(myCallback2); // Set up #1's callback. (Don't use Analog for buttons.)
myStepper.setMaxSpeed(1000);
myStepper.setSpeed(100);
}
// This is the guy that's called when the button1 changes state.
void myCallback2(void) {
if (!button1.trueFalse()) {
myStepper.setCurrentPosition(0);
positionOfReel = 2000;
myStepper.moveTo(positionOfReel);
myStepper.setSpeed(50);
if(myStepper.currentPosition()==400){
myStepper.setSpeed(400);
}
}
}
void myCallback1(void) {
if (!button1.trueFalse()) {
positionOfReel = 300;
myStepper.moveTo(position);
myStepper.setSpeed(30);
}
}
// Your standard sketch loop()
void loop() {
idle(); // Let all the idlers have time to do their thing.
myStepper.runSpeedToPosition();
}