Hi,
I hope this is the correct section for this post.
I have an Uno R3 hooked up to a TB660 stepper driver. I have 4 buttons going into the Uno. Depending on which button is pressed, the stepper turns a set number of times. 2 of the buttons are just a simple forward and reverse jog. The other 2 are much longer 'for' loops.
All of this is working, however, after pressing the button for one of the longer loops, the loops executes but then will not take any more button presses. If I disconnect the power, everything works again.
This does not happen every time, some of the time it completes the loop and then will jog or run one of the longer loops again if the buttons are pressed.
Is there something in my code that is preventing the system from continuing to monitor the buttons for presses?
My Code:
void setup()
{
pinMode(8, OUTPUT); // FORWARD(LEFT) = LOW; REVERSE(RIGHT) = HIGH
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
pinMode(2, INPUT_PULLUP); // BUTTON2 - 5GAL HEAD
pinMode(3, INPUT_PULLUP); // BUTTON3 - 15GAL HEAD
pinMode(4, INPUT_PULLUP); // BUTTON4 - LEFT JOG
pinMode(5, INPUT_PULLUP); // BUTTON5 - RIGHT JOG
}
void loop()
{
if (digitalRead(2) == LOW) // Button 2 PRESSED - 5GAL
{
for (int loop=0; loop<4000; loop++) // SET NUMBER OF LOOPS!!!!! 1000 = ~1"
{
digitalWrite(8, LOW); // TURN COUNTERCLOCKWISE - CUTTING
digitalWrite(9, HIGH);
delay(50); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
delay(10000); // PAUSE TO FINALLIZE CUT
for (int loop=0; loop<4000; loop++) // SET NUMBER OF LOOPS!!!!!
{
digitalWrite(8, HIGH); // TURN CLOCKWISE - RETREATING
digitalWrite(9, HIGH);
delay(25); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
}
if (digitalRead(3) == LOW) // Button 3 PRESSED - 15GAL
{
for (int loop=0; loop<3000; loop++) // SET NUMBER OF LOOPS!!!!! 1000 = ~1"
{
digitalWrite(8, LOW); // TURN COUNTERCLOCKWISE - CUTTING
digitalWrite(9, HIGH);
delay(50); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
delay(10000); // PAUSE TO FINALLIZE CUT
for (int loop=0; loop<3000; loop++) // SET NUMBER OF LOOPS!!!!!
{
digitalWrite(8, HIGH); // TURN CLOCKWISE - RETREATING
digitalWrite(9, HIGH);
delay(25); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
}
if (digitalRead(4) == LOW) // BUTTON 4 PRESSED - CLOCKWISE - LEFT ONCE
{
digitalWrite(8, LOW); // FORWARD - CUTTING
digitalWrite(9, HIGH);
delay(10); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
if (digitalRead(5) == LOW) // BUTTON 5 PRESSED - COUNTER-CLOCKWISE - RIGHT ONCE
{
digitalWrite(8, HIGH); // REVERSE - RETREATING
digitalWrite(9, HIGH);
delay(10); // ADJUST SPEED
digitalWrite(9, LOW);
delay(1); // ADJUST SPEED
}
}