C++ Arduino中正确的声明语法

C++ Arduino中正确的声明语法,c++,arduino,C++,Arduino,我是Arduino的新手,我从 当我尝试验证代码时,我得到 error: expected declaration before '}' token 在最后一行。我怎样才能修好它?再说一次,我是新手,所以如果你需要更多的细节,请告诉我 #include "pitch.h" // notes in the melody: int melody[] = {NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; // no

我是Arduino的新手,我从

当我尝试验证代码时,我得到

error: expected declaration before '}' token
在最后一行。我怎样才能修好它?再说一次,我是新手,所以如果你需要更多的细节,请告诉我

#include "pitch.h"

// notes in the melody:
int melody[] = {NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };

  void setup() {
  // iterate over the notes of the melody:
    for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    }
  }

  void loop() {
  // no need to repeat the melody.
  }
}
#包括“pitch.h”
//旋律中的音符:
int melody[]={NOTE_C4,NOTE_G3,NOTE_G3,NOTE_A3,NOTE_G3,0,NOTE_B3,NOTE_C4};
//音符持续时间:4=四分之一音符,8=八分之一音符等:
int noteDurations[]={
4, 8, 8, 4,4,4,4,4 };
无效设置(){
//重复旋律的音符:
对于(int thisNote=0;thisNote<8;thisNote++){
//要计算音符持续时间,请花费1秒
//除以音符类型。
//e、 g.四分之一音符=1000/4,八分之一音符=1000/8,等等。
int noteDuration=1000/注释持续时间[此注释];
音调(8,旋律[本音符],音符持续时间);
//要区分音符,请设置它们之间的最短时间。
//注释的持续时间+30%似乎效果良好:
int PAUSEBEETWEENOTES=注释持续时间*1.30;
延迟(暂停至两个点之间);
//停止播放音调:
诺通(8);
}
}
void循环(){
//不需要重复旋律。
}
}

代码末尾有一个额外的右括号
}
。删除最后一行中的一个,它不是必需的。

代码末尾有一个额外的右括号
}
。删除最后一行中的一个,不需要。

你应该事先学习C++,谢谢。您对如何解决这个特定问题有什么建议吗?setup()和loop()函数的缩进表明它们嵌套在某些内容中,但它们不是(据我所知,它们不需要嵌套)。这可能是导致额外的
}
的原因。建议将函数左移2列,使它们与<代码> >旋律> <代码>和<代码>注意持续时间对齐。您应该事先学习C++,谢谢。您对如何解决这个特定问题有什么建议吗?setup()和loop()函数的缩进表明它们嵌套在某些内容中,但它们不是(据我所知,它们不需要嵌套)。这可能是导致额外的
}
的原因。我建议将函数向左移动两列,以便它们与
melody
noteDurations
的声明对齐。我不确定我是否理解您的意思。我代码的最后一行有一个右括号。你指的是这句话吗?见鬼。我写了“分号”。我真傻。谢谢@KeithThompson的编辑。我不确定我是否理解你的意思。我代码的最后一行有一个右括号。你指的是这句话吗?见鬼。我写了“分号”。我真傻。感谢@KeithThompson的编辑。