[英]Arduino Compiling Error “Error compiling for board Arduino Nano”
我正在使用 Arduino Nano、帶有 NEMA17 步進器的 DRV8825 驅動器和 4 個按鈕來模擬稍后將使用的 ACS712 電流傳感器。 簡而言之,每個按鈕都連接到模擬引腳(A0、A1、A2、A3),模擬端口被編碼為特定的度數(0,45,225,270),經過一些工作,我能夠讓代碼按需要運行。 步進器響應按鈕並采用最短路徑(CW 或 CCW)到下一個選擇,無論選擇順序如何。 如果您使用 select 兩次相同的按鈕,它將保留在當前 position 中,因為它已經存在,因為這是一項正在進行的工作。 我正在一次進行一項更改,例如添加編碼以將繼電器的數字引腳寫入高電平,並將部分代碼轉換為數組。 這就是我為板 Arduino Nano 編譯錯誤的地方,我將包含 2 個代碼。 一個工作,一個給出編譯錯誤。 我希望我沒有違反任何規則,並且閱讀了一些似乎並不適用的結果。
在此處輸入代碼
//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);
} }
“為板 Arduino Nano 編譯錯誤”
只是錯誤信息的結尾。 帶有錯誤信息的實際錯誤消息在此之上。
我不會在這里詳細介紹 go,因為您的代碼格式非常糟糕,我不能簡單地復制粘貼它。 如果您需要其他人的幫助,您至少可以使用換行符發布您的代碼。 您不能在同一行中包含注釋和代碼。
首先映入我眼簾的是:
void loop(); int n; for (int index = 0; index < 4; index++)
如果您將有效的代碼與無法編譯的代碼進行比較,您會發現一些重要的差異。
例如,您有一個需要{
的分號。
void loop () {
// you code
}
現在向上滾動控制台,找出編譯器抱怨的問題並修復它。 如果您省略變量名並搜索通用文本,您可以在線找到任何錯誤消息的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.