Error compiling for board Arduino Nano

I am half scared to as a question after I have reading some replies. I am using an Arduino Nano, DRV8825 driver with a NEMA17 stepper, and 4 buttons to simulate ACS712 current sensors that will be used later. In short each button is attached to analog pins (A0,A1,A2,A3) and the analog ports are coded for specific degrees (0,45,225,270), After some work I was able to get the code to operate as wanted. The stepper response to the buttons and takes the shortest route to the next selection regardless of order of selection. As this is a work in progress, I am making changes one at a time such as adding coding to write a digital pin high for a relay after the stepper has move to position, and changing over to an array for portions. That’s where I am getting the Error compiling for board Arduino Nano.
I going to include 2 codes, one working and one that give the compile ERROR. I hope I have not violated any rules and i have read some results that didn’t seem to apply.

 THIS CODE GIVES THE ABOVE ERROR
[code]
//same as 1.0 but names changed to na=new angle  & CA=current angle
// This one seem to work,  had change some code to get it to work in all examples.
// Using buttons to simulate analog inputs for now.
// Adding led to represent vac relay on/off PIN 4

// defines pins numbers
const int stepPin = 3;
const int dirPin  = 2;
const int enPin  = 8;
const int vacPin = 4; //Just added this for vac

// Button asignments
//const int b1 = A0;
//const int b2 = A1;
//const int b3 = A2;
//const int b4 = A3;

const int PIN_COUNT = 4;
int inputPins[PIN_COUNT] = {A0, A1, A2, A3};
int outputVals[4] = {0, 45, 225, 270};

int ca = 0;  //currentAngle
int na = 0;  //angle
int stepPerAngle = 5 / 9; // full step = 1.8 or could have used "*1.8"
int   numstep;

void setup() {
  Serial.begin(9600);
  for (int index = 0; index < 4; index++)
    // Sets the 3 pins as Outputs
    pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);
  pinMode(vacPin, OUTPUT); //Just added this for vac

  //set values for 2 outputs
  digitalWrite(enPin, LOW);
  digitalWrite(dirPin, HIGH);
  digitalWrite(vacPin, LOW); //just add this for vac


  // set buttons as inputs,  some of these will become inputs from ACS712's
  /* pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A2, INPUT);
    pinMode(A3, INPUT);
    }*/

  void loop();
  int n;
  for (int index = 0; index < 4; index++)


    /* int n;
      // Assign button degrees
      if      ( digitalRead(A0) == HIGH) {
       na = 0;
      }
      else if ( digitalRead(A1) == HIGH) {
       na = 45;
      }
      else if ( digitalRead(A2) == HIGH) {
       na = 225;
      }
      else if ( digitalRead(A3) == HIGH) {
       na = 270;
      }*/

    //currentAngle=ca    new angle=na
    // 1st SCENARIO if these to ARE the same nothing happens
    //only if they ARE not equal then steps through to find a true statement to act ohn
    //if (ca = na) {digitalWrite(vacPin, HIGH);}
    if ( ca != na ) {
      //  Serial.println (ca);
      //2nd SCENARIO
      if (na - ca > 0 && na - ca <= 180)
      { digitalWrite(dirPin, HIGH);
        n = ((na - ca) * 5 / 9);
        numstep = n;
        ca = na;
      }

      //3rd SCENARIO
      else if (ca - na > 0 && ca - na > 180)
      { digitalWrite(dirPin, HIGH);
        n = ((na + 360 - ca) * 5 / 9);
        numstep = n;
        ca = na;
      }

      // 4th SCENARIO
      else if (na - ca < 0 && na - ca <= 180)
      { digitalWrite(dirPin, LOW);
        n = ((ca - na) * 5 / 9);
        numstep = n;
        ca = na; (ca);
      }

      //5th SCENARIO
      else if (na - ca > 0 && na - ca > 180)
      { digitalWrite(dirPin, LOW);
        n = ((ca + 360 - na) * 5 / 9);
        numstep = n;
        ca = na; (ca);
      }

      for (int x = 0; x < numstep; x++) {

        digitalWrite(stepPin, HIGH);
        delayMicroseconds(1000);  //speed
        digitalWrite(stepPin, LOW);
        delayMicroseconds(1000);
      }  //speed
      delay(500);
    }
}
THIS ONE WORKS WITH NO ERRORS
//same as 1.0 but names changed to na=new angle  & CA=current angle
// This one seem to work,  had change some code to get it to work in all examples.
// Using buttons to simulate analog inputs for now.
// Adding led to represent vac relay on/off PIN 4

// defines pins numbers
const int stepPin = 3;
const int dirPin  = 2;
const int enPin  = 8;
const int vacPin = 4; //Just added this for vac

// Button asignment
//const int b1 = A0;
//const int b2 = A1;
//const int b3 = A2;
//const int b4 = A3;

int ca = 0;  //currentAngle
int na = 0;  //angle
int stepPerAngle = 5 / 9; // full step = 1.8 or could have used "*1.8"
int   numstep;

void setup() {
  Serial.begin(9600);

  // Sets the 3 pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);
  pinMode(vacPin, OUTPUT); //Just added this for vac

  //set values for 2 outputs
  digitalWrite(enPin, LOW);
  digitalWrite(dirPin, HIGH);
  digitalWrite(vacPin, LOW); //just add this for vac


  // set buttons as inputs,  some of these will become inputs from ACS712's
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
}

void loop() {
  int n;
  // Assign button degrees
  if      ( digitalRead(A0) == HIGH) {
    na = 0;
  }
  else if ( digitalRead(A1) == HIGH) {
    na = 45;
  }
  else if ( digitalRead(A2) == HIGH) {
    na = 225;
  }
  else if ( digitalRead(A3) == HIGH) {
    na = 270;
  }

  //currentAngle=ca    new angle=na
  // 1st SCENARIO if these to ARE the same nothing happens
  //only if they ARE not equal then steps through to find a true statement to act ohn
  //if (ca = na) {digitalWrite(vacPin, HIGH);}
  if ( ca != na ) {
    //  Serial.println (ca);
    //2nd SCENARIO
    if (na - ca > 0 && na - ca <= 180)
    { digitalWrite(dirPin, HIGH);
      n = ((na - ca) * 5 / 9);
      numstep = n;
      ca = na;
    }

    //3rd SCENARIO
    else if (ca - na > 0 && ca - na > 180)
    { digitalWrite(dirPin, HIGH);
      n = ((na + 360 - ca) * 5 / 9);
      numstep = n;
      ca = na;
    }

    // 4th SCENARIO
    else if (na - ca < 0 && na - ca <= 180)
    { digitalWrite(dirPin, LOW);
      n = ((ca - na) * 5 / 9);
      numstep = n;
      ca = na; (ca);
    }

    //5th SCENARIO
    else if (na - ca > 0 && na - ca > 180)
    { digitalWrite(dirPin, LOW);
      n = ((ca + 360 - na) * 5 / 9);
      numstep = n;
      ca = na; (ca);
    }

    for (int x = 0; x < numstep; x++) {

      digitalWrite(stepPin, HIGH);
      delayMicroseconds(1000);  //speed
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1000);
    }  //speed
    delay(500);
  }
}

[/code]

Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and post it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link that will allow you to make the attachment.

Nice job with code tags on your first post. :slight_smile:

Where does setup() end?
Where does loop() begin?

  // set buttons as inputs,  some of these will become inputs from ACS712's
  /* pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A2, INPUT);
    pinMode(A3, INPUT);
    }*/

  void loop();
  int n;

You commented out a little too much.

void loop();Oops.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.