首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino编译错误"Error Compiling for board Arduino Nano“

Arduino编译错误"Error Compiling for board Arduino Nano“
EN

Stack Overflow用户
提问于 2021-03-19 00:20:18
回答 1查看 102关注 0票数 0

我使用的是Arduino Nano,带有NEMA17步进器的DRV8825驱动器,以及4个按钮来模拟稍后将使用的ACS712电流传感器。简而言之,每个按钮都连接到模拟引脚(A0,A1,A2,A3),并且模拟端口被编码为特定的度数(0,45,225,270),经过一些工作,我能够使代码按所需的方式运行。步进器响应按钮并采用最短路径(CW或CCW)进行下一次选择,而不考虑选择顺序。如果您选择同一按钮两次,它将保持在当前位置,因为它已经在那里了!由于这是一项正在进行的工作,我一次做一个更改,例如添加代码以将继电器的数字引脚写为高电平,并转换为部分代码的数组。这就是我在编译Arduino Nano板时遇到错误的地方。我将包含2个代码,一个正常工作,另一个给出编译错误。我希望我没有违反任何规则,并阅读了一些似乎不适用的结果。

在此处输入代码

代码语言:javascript
复制
                         //THIS ONE GIVE THE ABOVE ERROR//

  //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 COMPILES 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);
} }
EN

回答 1

Stack Overflow用户

发布于 2021-03-19 03:16:58

“编译主板Arduino Nano时出错”

只是错误消息的结尾。包含what is error信息的实际错误消息在此之上。

我不会在这里详细介绍,因为您的代码格式太差了,我不能简单地复制粘贴它。如果你需要别人的帮助,你至少可以用换行符来发布你的代码。注释和代码不能在同一行中。

我看到的第一件事是:

代码语言:javascript
复制
void loop(); int n; for (int index = 0; index < 4; index++)

如果您将运行正常的代码与未编译的代码进行比较,您会发现一些重要的差异。

例如,在需要{的地方有一个分号。

代码语言:javascript
复制
void loop () {
  // you code
}

现在向上滚动控制台,找出编译器在抱怨什么并修复它。如果省略变量名并搜索常见文本,则可以在线找到任何错误消息的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66695020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档