首页 > 解决方案 > 函数定义 1 错误,我尝试在我的 arduino ide 中自动格式化并按 ctrl+t,但问题仍然存在

问题描述

我不断收到这些 Buzzer-CLiCK:33:19: error: a function-definition is not allowed before '{' token void circling() { ^ Buzzer-CLiCK:40:17: error: a function-definition is not allowed在 '{' token 之前 void stopc () { ^ exit status 1 在 '{' token 之前不允许函数定义

下面是我的代码

const int BUTTON_PIN = 0; // Arduino pin connected to button's pin
const int BUZZER_PIN = 12; // Arduino pin connected to Buzzer's pin
const int LED_1 = 13;
int point;
int pin[] = {9, 8, 7, 6, 2, 3, 4, 5};

void setup() {
  Serial.begin(9600);
  for (int i = 0 ; i <= 7; i++) { // initialize serial
    pinMode(pin[i], OUTPUT);
    pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
    pinMode(BUZZER_PIN, OUTPUT);       // set arduino pin to output mode

  }
}

void loop() {
  int buttonState = digitalRead(BUTTON_PIN); // read new state

  if (buttonState == LOW) {
    Serial.println("The button is being pressed");
    digitalWrite(BUZZER_PIN, HIGH); // turn on
    digitalWrite(LED_1, HIGH);
circling();


  }
  else if (buttonState == HIGH) {
    Serial.println("The button is unpressed");
    digitalWrite(BUZZER_PIN, LOW);  // turn off
    digitalWrite(LED_1, LOW);
stopc();
  }

  void circling() {
    for (int i = 0; i <= 7 ; i++) {
      digitalWrite(pin[i], HIGH);
      digitalWrite(pin[i], LOW);
    }
  }

  void stopc () {
    for (int i = 0 ; i <= 7; i++) {
      digitalWrite(pin[i], LOW);
    }
  }
}

标签: arduinoarduino-uno

解决方案


推荐阅读