大家好,新人學習arduino。遇到了一個奇怪 的問題。
提示:expected initializer before numeric constant,數值常量之前應為初始值設定項
按我理解第一步預定義常量不就是在設定初始值嗎?附上程序和報錯信息。
請大佬指點一二。謝謝!
程序:
const int BUTTON_A 7
const int BUTTON_B 8
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN,OUTPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (LOW == digitalRead(BUTTON_A){
bool FLAG_A = 1;
unsigned long time_A_init = millis();
}
if (FLAG_A){
if (millis()-time_A_init > SET_A){
digitalWrite(LED_BUILTIN,HIGH);
FLAG_A = 0;
time_A_init = 0;
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
}
}
}
報錯信息
Arduino:1.8.5 (Windows 7), 開發板:"Arduino/Genuino Uno"
20200708_DELAY:2: error: expected initializer before numeric constant
const int BUTTON_A 7
^
D:\Alan wu\Arduino\20200708_DELAY\20200708_DELAY.ino: In function 'void loop()':
20200708_DELAY:16: error: 'BUTTON_A' was not declared in this scope
if (LOW == digitalRead(BUTTON_A){
^
20200708_DELAY:16: error: expected ')' before '{' token
if (LOW == digitalRead(BUTTON_A){
^
20200708_DELAY:29: error: expected primary-expression before '}' token
}
^
exit status 1
expected initializer before numeric constant
在文件 -> 首選項開啟
“編譯過程中顯示詳細輸出”選項
這份報告會包含更多信息。
|