//DUp;icator Motor Control
// Defin pins
const int engagefull = 2; // start full button
const int engagehalf = 3; // start half button
const int start = 4; //out to enable pin
const int driverPUL = 5; // PUL- pin
// Variables
int pd = 3000; // pulse delay period determines speed (increase to slow)
int myCounter = 0; // initial counter state
int RotAmount = 50; // initial amount of steps for motor
boolean enable = HIGH; // start motor state
void setup() {
delay(1000);
digitalWrite(start,enable); // start motor
pinMode (driverPUL, OUTPUT); //set pin to output
pinMode (start, OUTPUT); //set pin to output
pinMode (engagefull, INPUT_PULLUP);
pinMode (engagehalf, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(engagefull), enablemotorfull, FALLING); //makes the button do a thing
attachInterrupt(digitalPinToInterrupt(engagehalf), enablemotorhalf, FALLING); //makes the button do a thing
}
void enablemotorfull (){ // when full button is pressed, set RotAmount to 50 steps
enable = LOW;
myCounter = 0; // reset counter
RotAmount = 50;
}
void enablemotorhalf (){ // when half button is pressed, set RotAmount to 25 steps
enable = LOW;
myCounter = 0; // reset counter
RotAmount = 25;
}
void loop() {
if(myCounter<=RotAmount) { // sets how many times loop runs
digitalWrite(driverPUL,HIGH); // generat pulse signal pos
delayMicroseconds(pd); // pos pulse length
digitalWrite(driverPUL,LOW);// generat pulse signal pneg
delayMicroseconds(pd); // neg pulse length
myCounter = myCounter + 1;
}
}