After about 2-3 times of the loop running, the code goes to "abort" despite not pressing the button. Any idea why?
enum DIR_ENUM {
DIR_UP = 0, // Black
DIR_DN, // Blue
DIR_LT, // Yellow
DIR_RT, // Green
DIR_CNT
};
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int DirectionPin[DIR_CNT] = {10, 8, 6, 4};
int OppositesPin[DIR_CNT] = {8, 10, 4, 6};
int Steps [100][2];
int Accumulation [DIR_CNT][2];
int Purple = 12;
boolean running = HIGH;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Steps[0][0] = DIR_UP;
Steps[0][1] = 2000; //delay for 2 seconds
Steps[1][0] = DIR_DN;
Steps[1][1] = 2000;
Steps[2][0] = DIR_LT;
Steps[2][1] = 4000;
Steps[3][0] = DIR_RT;
Steps[3][1] = 4000;
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (running)
{
digitalWrite(ledPin, LOW);
//UP
Serial.println("UP");
digitalWrite(DirectionPin[Steps[0][0]], HIGH); // Go UP for 2 seconds
delay(Steps[0][1]);
digitalWrite(DirectionPin[Steps[0][0]], LOW);
//DOWN
Serial.println("DOWN");
digitalWrite(DirectionPin[Steps[1][0]], HIGH); // Go DOWN for 2 seconds
delay(Steps[1][1]);
digitalWrite(DirectionPin[Steps[1][0]], LOW);
//LEFT
Serial.println("LEFT");
digitalWrite(DirectionPin[Steps[2][0]], HIGH); // Go LEFT for 4 seconds
delay(Steps[2][1]);
digitalWrite(DirectionPin[Steps[2][0]], LOW);
//RIGHT
Serial.println("RIGHT");
digitalWrite(DirectionPin[Steps[3][0]], HIGH); // Go RIGHT for 4 seconds
delay(Steps[3][1]);
digitalWrite(DirectionPin[Steps[3][0]], LOW);
}
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
Serial.println("abort");
digitalWrite(ledPin, HIGH);
while(1);
}
}





